feat(nvim): improve cmp + luasnip keybinds

This commit is contained in:
Moritz Böhme 2024-02-11 21:13:50 +01:00
parent e87d0c7ec3
commit 96697c684c
Signed by: moritz
GPG key ID: 970C6E89EB0547A9

View file

@ -10,6 +10,9 @@ cmp.setup({
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
}), }),
}, },
enabled = function()
return not luasnip.jumpable(1)
end,
snippet = { snippet = {
-- REQUIRED - you must specify a snippet engine -- REQUIRED - you must specify a snippet engine
expand = function(args) expand = function(args)
@ -23,19 +26,19 @@ cmp.setup({
["<S-CR>"] = cmp.mapping.abort(), ["<S-CR>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), ["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then if cmp.visible() then
luasnip.jump(1)
elseif cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.jumpable(1) then
luasnip.jump(1)
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then if cmp.visible() then
luasnip.jump(-1)
elseif cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else else
fallback() fallback()
end end
@ -43,8 +46,6 @@ cmp.setup({
["<C-n>"] = cmp.mapping(function(fallback) ["<C-n>"] = cmp.mapping(function(fallback)
if luasnip.choice_active() then if luasnip.choice_active() then
luasnip.change_choice(1) luasnip.change_choice(1)
elseif cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else else
fallback() fallback()
end end
@ -52,8 +53,6 @@ cmp.setup({
["<C-p>"] = cmp.mapping(function(fallback) ["<C-p>"] = cmp.mapping(function(fallback)
if luasnip.choice_active() then if luasnip.choice_active() then
luasnip.change_choice(-1) luasnip.change_choice(-1)
elseif cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
else else
fallback() fallback()
end end