From 96697c684cd1980e8a4cfd746e053b605645e49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 11 Feb 2024 21:13:50 +0100 Subject: [PATCH] feat(nvim): improve cmp + luasnip keybinds --- .../programs/nvim/plugins/lua/nvim-cmp.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/programs/nvim/plugins/lua/nvim-cmp.lua b/modules/programs/nvim/plugins/lua/nvim-cmp.lua index 4b9c067..19d9ffe 100644 --- a/modules/programs/nvim/plugins/lua/nvim-cmp.lua +++ b/modules/programs/nvim/plugins/lua/nvim-cmp.lua @@ -10,6 +10,9 @@ cmp.setup({ ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead }), }, + enabled = function() + return not luasnip.jumpable(1) + end, snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) @@ -23,19 +26,19 @@ cmp.setup({ [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) - if luasnip.jumpable(1) then - luasnip.jump(1) - elseif cmp.visible() then + if cmp.visible() then cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + elseif luasnip.jumpable(1) then + luasnip.jump(1) else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) - if luasnip.jumpable(-1) then - luasnip.jump(-1) - elseif cmp.visible() then + if cmp.visible() then cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) else fallback() end @@ -43,8 +46,6 @@ cmp.setup({ [""] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(1) - elseif cmp.visible() then - cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) else fallback() end @@ -52,8 +53,6 @@ cmp.setup({ [""] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(-1) - elseif cmp.visible() then - cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) else fallback() end