nvim/lua/init-cmp.lua

50 lines
1.4 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-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = 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',
option = {
keyword_length = 4,
max_item_count = 20,
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end
}},
{name = 'ultisnips', priority_weight = 10, keyword_length = 1}
}
})