nvimrc: switch to nvim-cmp plugin

This commit is contained in:
Rob Watson 2021-10-27 09:36:22 +02:00
parent 0ae989dc84
commit 8be560abe1
1 changed files with 23 additions and 73 deletions

96
nvimrc
View File

@ -68,7 +68,7 @@ set updatetime=250
set pastetoggle=<f2>
set pumheight=200
" Required for nvim-compe:
set completeopt=menuone,noselect
set completeopt=menu,menuone,noselect
set complete-=i
set nrformats-=octal
set ttimeout
@ -768,80 +768,30 @@ nvim_lsp.sumneko_lua.setup {
}
EOF
" nvim-compe:
" nvim-cmp:
packadd! nvim-compe " https://github.com/hrsh7th/nvim-compe
packadd! compe-tmux " https://github.com/andersevenrud/compe-tmux
packadd! nvim-cmp " https://github.com/hrsh7th/nvim-cmp.git
packadd! cmp-nvim-lsp " https://github.com/hrsh7th/cmp-nvim-lsp.git
packadd! cmp-buffer " https://github.com/hrsh7th/cmp-buffer.git
packadd! cmp-path " https://github.com/hrsh7th/cmp-path.git
packadd! cmp-calc " https://github.com/hrsh7th/cmp-calc
lua <<EOF
require 'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
resolve_timeout = 800;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = true;
local cmp = require('cmp')
source = {
path = true;
buffer = true;
calc = true;
nvim_lsp = true;
nvim_lua = true;
vsnip = false;
ultisnips = false;
tmux = true;
treesitter = false;
};
}
EOF
inoremap <silent><expr> <C-y> compe#confirm('<C-y>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
" TAB navigation support:
lua <<EOF
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
cmp.setup({
mapping = {
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'calc' },
})
})
EOF