nvim/lua/init-cmp.lua

56 lines
1.0 KiB
Lua

local cmp = require'cmp'
cmp.setup({
formatting = {
format = function(entry, vim_item)
-- set a name for each source
vim_item.menu = ({
nvim_lsp = "[LSP]",
path = "[Path]",
buffer = "[Buffer]",
dictionary = "[Dict]",
ultisnips = "[UltiSnips]",
})[entry.source.name]
return vim_item
end,
},
completion = {
keyword_length = 4,
-- autocomplete = false
},
snippet = {
expand = function(args)
vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = {
['<C-n>'] = cmp.mapping.complete(),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
-- ['<C-e>'] = cmp.mapping.close(),
['<C-e>'] = cmp.mapping.abort(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-u>'] = cmp.mapping.scroll_docs(4),
},
sources = {
{
name = 'nvim_lsp',
max_item_count = 8,
},
{ name = 'path' },
{
name = 'buffer',
max_item_count = 20,
},
{
name = 'dictionary',
keyword_length = 4,
max_item_count = 20,
},
{
name = 'ultisnips',
priority_weight = 10,
keyword_length = 2,
},
...
}
})