neovim: asynchronous loading in init.lua

Also fix luasnip mapping for nvim-cmp
This commit is contained in:
FollieHiyuki 2021-09-10 00:34:09 +07:00
parent f6b969a931
commit a747daeacd
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
3 changed files with 45 additions and 41 deletions

View File

@ -1,36 +1,14 @@
local disable_default_plugins = function() local async
vim.g.loaded_gzip = 1 async = vim.loop.new_async(vim.schedule_wrap(function()
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()
require('plugins') require('plugins')
require('mappings') require('mappings')
require('events').load_autocmds() 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()

View File

@ -69,14 +69,14 @@ function M.cmp_conf()
-- Change choice nodes for luasnip -- Change choice nodes for luasnip
['<C-h>'] = cmp.mapping(function(fallback) ['<C-h>'] = cmp.mapping(function(fallback)
if luasnip.choice_active() then if luasnip.choice_active() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-prev-choice', true, true, true), '') vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-prev-choice', true, true, true), '', true)
else else
fallback() fallback()
end end
end, {'i', 's'}), end, {'i', 's'}),
['<C-l>'] = cmp.mapping(function(fallback) ['<C-l>'] = cmp.mapping(function(fallback)
if luasnip.choice_active() then if luasnip.choice_active() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-next-choice', true, true, true), '') vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-next-choice', true, true, true), '', true)
else else
fallback() fallback()
end end
@ -86,7 +86,7 @@ function M.cmp_conf()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n', true) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n', true)
elseif has_words_before() and luasnip.expand_or_jumpable() then elseif has_words_before() and luasnip.expand_or_jumpable() then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '') vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '', true)
else else
fallback() fallback()
end end

View File

@ -1,6 +1,36 @@
local opt = vim.opt 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 -- General settings
opt.termguicolors = true opt.termguicolors = true
opt.mouse = 'nv' opt.mouse = 'nv'
@ -120,10 +150,6 @@ local function load_options()
-- Undo file path -- Undo file path
opt.undofile = true opt.undofile = true
opt.undodir = vim.fn.stdpath('cache') .. '/undodir' 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 end
load_options() return M