dotfiles/neovim/.config/nvim/lua/cmp-lsp.lua
Gabe Venberg 1256688237 fixed autocomplete behavior.
Previously, when you didnt want to do any completion and tried to put a
newline directly after, nvim would intrepret the enter as choosing the
first completion entry.
2022-09-22 15:01:33 -05:00

71 lines
1.6 KiB
Lua

--configure nvim-cmp for use with lsp and luasnip.
local luasnip = require 'luasnip'
-- Set completeopt to have a better completion experience
vim.o.completeopt='menu,menuone,preview,noinsert,noselect'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = false,
-- behavior = cmp.ConfirmBehavior.Replace,
-- select = false,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'emoji' },
{ name = 'latex_symbols' },
-- { name = 'buffer' },
-- { name = 'digraphs' },
-- { name = 'dictionary' },
-- { name = 'spell' },
},
}
cmp.setup.cmdline('/', {
sources = cmp.config.sources({
{ name = 'nvim_lsp_document_symbol' },
{ name = 'treesitter' },
}, {
{ name = 'buffer' },
{ name = 'cmdline' },
})
})