From 851bf58b21515c5cce4011eabddc66e9a5d027c8 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:24:29 +0200 Subject: [PATCH] nvim: Improve snippet jumping Snippets can be jumped through more easily now since jumping between snippets (with and ) takes precedence over completions and jumping through completions. That means when a snippet has been expanded we can now cycle through its insertion points without worrying about activating completion items instead. Additionally, only jump through insertion points as long as we are within the snippet boundaries with the cursor, so it doesn't surprise jump later when pressing from somewhere else in the file. --- nvim/.config/nvim/lua/plugins/completion.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/completion.lua b/nvim/.config/nvim/lua/plugins/completion.lua index cb5a3fc..a97c9bb 100644 --- a/nvim/.config/nvim/lua/plugins/completion.lua +++ b/nvim/.config/nvim/lua/plugins/completion.lua @@ -135,12 +135,12 @@ return { }), -- disable selection in cmd mode }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- they way you will only jump inside the snippet region - elseif luasnip.expand_or_jumpable() then + -- expand_or_jumpable() will always jump + -- expand_or_locally_jumpable() only jumps when still inside snippet region + if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() + elseif cmp.visible() then + cmp.select_next_item() elseif has_words_before() then cmp.complete() else @@ -148,10 +148,10 @@ return { end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then + if luasnip.jumpable(-1) then luasnip.jump(-1) + elseif cmp.visible() then + cmp.select_prev_item() else fallback() end