From 123f8d229eef05869ee4c98dfd4934c22a03b1f6 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Fri, 14 Mar 2025 09:51:52 +0100 Subject: feat(snippet): set snippet keymaps permanent instead of dynamic (#31887) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Given that `vim.snippet.expand()` sets temporary ``/`` keymaps there is no way to build "smart-tab" functionality where `` chooses the next completion candidate if the popup menu is visible. Solution: Set the keymap permanent in `_defaults`. The downside of this approach is that users of multiple snippet engine's need to adapt their keymaps to handle all their engines that are in use. For example: vim.keymap.set({ 'i', 's' }, "", function() if foreign_snippet.active() then return "lua require('foreign_snippet').jump()" elseif vim.snippet.active({ direction = 1 }) then return "lua vim.snippet.jump(1)" else return key end end, { expr = true }) Upside is that using `vim.keymap.set` to override keymaps is a well established pattern and `vim.snippet.expand` calls made by nvim itself or plugins have working keymaps out of the box. Co-authored-by: Maria José Solano --- test/functional/plugin/lsp/completion_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 8d362642de..94578aa6da 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -1241,7 +1241,9 @@ describe('vim.lsp.completion: integration', function() } end) ) - feed('') + exec_lua(function() + vim.snippet.jump(1) + end) eq( #'hello friends', exec_lua(function() -- cgit