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 pastetoggle=<f2>
set pumheight=200 set pumheight=200
" Required for nvim-compe: " Required for nvim-compe:
set completeopt=menuone,noselect set completeopt=menu,menuone,noselect
set complete-=i set complete-=i
set nrformats-=octal set nrformats-=octal
set ttimeout set ttimeout
@ -768,80 +768,30 @@ nvim_lsp.sumneko_lua.setup {
} }
EOF EOF
" nvim-compe: " nvim-cmp:
packadd! nvim-compe " https://github.com/hrsh7th/nvim-compe packadd! nvim-cmp " https://github.com/hrsh7th/nvim-cmp.git
packadd! compe-tmux " https://github.com/andersevenrud/compe-tmux 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 lua <<EOF
require 'compe'.setup { local cmp = require('cmp')
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;
source = { cmp.setup({
path = true; mapping = {
buffer = true; ['<C-u>'] = cmp.mapping.scroll_docs(-4),
calc = true; ['<C-d>'] = cmp.mapping.scroll_docs(4),
nvim_lsp = true; ['<C-Space>'] = cmp.mapping.complete(),
nvim_lua = true; ['<C-e>'] = cmp.mapping.close(),
vsnip = false; ['<CR>'] = cmp.mapping.confirm({ select = true }),
ultisnips = false; },
tmux = true; sources = cmp.config.sources({
treesitter = false; { name = 'nvim_lsp' },
}; { name = 'buffer' },
} { name = 'path' },
EOF { name = 'calc' },
})
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})
EOF EOF