From 4f5445cc0ee610ef2aab28621076cc594109c70d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 16 Jun 2024 16:40:10 +0200 Subject: [PATCH] nvim: Add function to cleanly unmap keys Removes them from being active in vim as well as removing them from being displayed in which-key. Unfortunately the which-key implementation still seems broken, sometimes removing them sometimes leaving them as-is. --- nvim/.config/nvim/lua/core/util.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/nvim/.config/nvim/lua/core/util.lua b/nvim/.config/nvim/lua/core/util.lua index d83d8f0..6279973 100644 --- a/nvim/.config/nvim/lua/core/util.lua +++ b/nvim/.config/nvim/lua/core/util.lua @@ -17,6 +17,17 @@ function T.get_plugin(plugin) return nil end +-- Remove the key from the vim keymap and from being displayed in which-key +-- FIXME This does not consistently currently with which-key +-- Every once in a while the maps are correctly hidden but other times they stay? +function T.unmap_key(lhs, mode) + mode = mode or "n" + if T.is_available("which-key") then + vim.keymap.set(mode, lhs, "", { desc = "which_key_ignore", silent = true }) + end + pcall(vim.keymap.del, mode, lhs) +end + -- from https://github.com/ray-x/navigator.lua/issues/247#issue-1465308677 local function path_join(...) return table.concat(vim.tbl_flatten({ ... }), "/")