home: vim: completion: configure snippets

This commit is contained in:
Bruno BELANYI 2022-03-07 18:08:54 +01:00
parent df92d1c562
commit 435e56d53a

View file

@ -4,8 +4,14 @@ set completeopt=menu,menuone,noselect
lua << EOF
local cmp = require("cmp")
local cmp_under_comparator = require("cmp-under-comparator")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<Down>"] = cmp.mapping({
i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
@ -23,32 +29,24 @@ cmp.setup({
fallback()
end,
}),
["<Tab>"] = cmp.mapping({
c = function(fallback)
if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then
["<Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
cmp.complete()
end
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
}),
["<S-Tab>"] = cmp.mapping({
c = function(fallback)
if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then
["<S-Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
cmp.complete()
end
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
}),
["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), { "i", "c" }),
["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), { "i", "c" }),
["<C-d>"] = cmp.mapping.scroll_docs(-5),
@ -63,6 +61,7 @@ cmp.setup({
{ name = "path", priority_weight = 110 },
{ name = "nvim_lsp", priority_weight = 100 },
{ name = "nvim_lua", priority_weight = 90 },
{ name = "luasnip", priority_weight = 80 },
{ name = "buffer", max_item_count = 5, priority_weight = 50 },
},
sorting = {