home: vim: completion: configure snippets

This commit is contained in:
Bruno BELANYI 2022-03-07 18:08:54 +01:00
parent 551ef640fc
commit 01f2dfd028

View file

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