From a747daeacdbe663e9566b303942aaa658c665d73 Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Fri, 10 Sep 2021 00:34:09 +0700 Subject: [PATCH] neovim: asynchronous loading in init.lua Also fix luasnip mapping for nvim-cmp --- home/.config/nvim/init.lua | 42 +++++--------------- home/.config/nvim/lua/modules/completion.lua | 6 +-- home/.config/nvim/lua/options.lua | 38 +++++++++++++++--- 3 files changed, 45 insertions(+), 41 deletions(-) diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index c1f092a..57ef4ef 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -1,36 +1,14 @@ -local disable_default_plugins = function() - vim.g.loaded_gzip = 1 - vim.g.loaded_tar = 1 - vim.g.loaded_tarPlugin = 1 - vim.g.loaded_zip = 1 - vim.g.loaded_zipPlugin = 1 - vim.g.loaded_getscript = 1 - vim.g.loaded_getscriptPlugin = 1 - vim.g.loaded_vimball = 1 - vim.g.loaded_vimballPlugin = 1 - vim.g.loaded_matchit = 1 - vim.g.loaded_matchparen = 1 - vim.g.loaded_2html_plugin = 1 - vim.g.loaded_logiPat = 1 - vim.g.loaded_rrhelper = 1 - vim.g.loaded_netrw = 1 - vim.g.loaded_netrwPlugin = 1 - vim.g.loaded_netrwSettings = 1 - vim.g.loaded_netrwFileHandlers = 1 -end - -local load_core = function() - -- Global theme - vim.g.global_theme = 'nord' - - -- Config - vim.g.mapleader = ' ' - disable_default_plugins() - require('options') - require('colors.' .. vim.g.global_theme).highlight() +local async +async = vim.loop.new_async(vim.schedule_wrap(function() require('plugins') require('mappings') require('events').load_autocmds() -end + async:close() +end)) -load_core() +local options = require('options') + +options.disable_default_plugins() +options.load_options() +require('colors.' .. vim.g.global_theme).highlight() +async:send() diff --git a/home/.config/nvim/lua/modules/completion.lua b/home/.config/nvim/lua/modules/completion.lua index fbdecdb..35a6eb1 100644 --- a/home/.config/nvim/lua/modules/completion.lua +++ b/home/.config/nvim/lua/modules/completion.lua @@ -69,14 +69,14 @@ function M.cmp_conf() -- Change choice nodes for luasnip [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-prev-choice', true, true, true), '') + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-prev-choice', true, true, true), '', true) else fallback() end end, {'i', 's'}), [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-next-choice', true, true, true), '') + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-next-choice', true, true, true), '', true) else fallback() end @@ -86,7 +86,7 @@ function M.cmp_conf() if vim.fn.pumvisible() == 1 then vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n', true) elseif has_words_before() and luasnip.expand_or_jumpable() then - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '', true) else fallback() end diff --git a/home/.config/nvim/lua/options.lua b/home/.config/nvim/lua/options.lua index 920b863..09a21c8 100644 --- a/home/.config/nvim/lua/options.lua +++ b/home/.config/nvim/lua/options.lua @@ -1,6 +1,36 @@ local opt = vim.opt +local M = {} + +function M.disable_default_plugins() + vim.g.loaded_gzip = 1 + vim.g.loaded_tar = 1 + vim.g.loaded_tarPlugin = 1 + vim.g.loaded_zip = 1 + vim.g.loaded_zipPlugin = 1 + vim.g.loaded_getscript = 1 + vim.g.loaded_getscriptPlugin = 1 + vim.g.loaded_vimball = 1 + vim.g.loaded_vimballPlugin = 1 + vim.g.loaded_matchit = 1 + vim.g.loaded_matchparen = 1 + vim.g.loaded_2html_plugin = 1 + vim.g.loaded_logiPat = 1 + vim.g.loaded_rrhelper = 1 + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + vim.g.loaded_netrwSettings = 1 + vim.g.loaded_netrwFileHandlers = 1 +end + +function M.load_options() + -- Global theme + vim.g.global_theme = 'nord' + -- Leader key + vim.g.mapleader = ' ' + -- Python path + vim.g.python_host_prog = '/usr/bin/python' + vim.g.python3_host_prog = '/usr/bin/python3' -local function load_options() -- General settings opt.termguicolors = true opt.mouse = 'nv' @@ -120,10 +150,6 @@ local function load_options() -- Undo file path opt.undofile = true opt.undodir = vim.fn.stdpath('cache') .. '/undodir' - - -- Python path - vim.g.python_host_prog = '/usr/bin/python' - vim.g.python3_host_prog = '/usr/bin/python3' end -load_options() +return M