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.
This commit is contained in:
Marty Oehme 2024-06-16 16:40:10 +02:00
parent 3e13941eae
commit 4f5445cc0e
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -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({ ... }), "/")