nvim/lua/plugin/cmp.lua
2024-05-30 17:05:02 +02:00

42 lines
1,019 B
Lua

local cmp = require('cmp')
cmp.setup({
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = false }),
['<C-e>'] = cmp.mapping.abort(),
['<Up>'] = cmp.mapping.select_prev_item({ behavior = 'select' }),
['<Down>'] = cmp.mapping.select_next_item({ behavior = 'select' }),
['<Tab>'] = cmp.mapping.select_next_item({ behavior = 'select' }),
['<C-p>'] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item({ behavior = 'insert' })
else
cmp.complete()
end
end),
['<C-n>'] = cmp.mapping(function()
if cmp.visible() then
cmp.select_next_item({ behavior = 'insert' })
else
cmp.complete()
end
end),
},
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
})
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)