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.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
else elseif luasnip.expand_or_jumpable() then
cmp.complete() luasnip.expand_or_jump()
end
else else
fallback() fallback()
end end
end, end,
}), ["<S-Tab>"] = function(fallback)
["<S-Tab>"] = cmp.mapping({
c = function(fallback)
if #cmp.core:get_sources() > 0 and not require("cmp.config").is_native_menu() then
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
else elseif luasnip.jumpable(-1) then
cmp.complete() luasnip.jump(-1)
end
else else
fallback() fallback()
end end
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 = {