nvim/lua/init-cmp.lua

42 lines
1.3 KiB
Lua

local cmp = require 'cmp'
cmp.setup({
window = {documentation = cmp.config.window.bordered({border = "single"})},
formatting = {
format = function(entry, vim_item)
-- set a name for each source
vim_item.menu = ({
nvim_lsp = "[LSP]",
path = "[Path]",
buffer = "[Buffer]",
ultisnips = "[UltiSnips]"
})[entry.source.name]
return vim_item
end
},
completion = {
keyword_length = 1,
max_item_count = 20
-- autocomplete = false
},
snippet = {expand = function(args) vim.fn["UltiSnips#Anon"](args.body) end},
mapping = {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-u>'] = cmp.mapping.scroll_docs(4),
["<C-n>"] = cmp.mapping({
i = function()
if cmp.visible() then
cmp.select_next_item({behavior = cmp.SelectBehavior.Insert})
else
cmp.complete()
end
end
})
},
sources = {
{name = 'nvim_lsp', max_item_count = 8, keyword_length = 3},
{name = 'path'},
{name = 'buffer', keyword_length = 4, max_item_count = 20},
{name = 'ultisnips', priority_weight = 10, keyword_length = 1}
}
})