which-key.nvim
which-key.nvim copied to clipboard
feature: alias for which-key bindings
Did you check the docs?
- [X] I have read all the which-key.nvim docs
Is your feature request related to a problem? Please describe.
As #160 says, there are times when we don't want to define our own set of keys, but rather use the keys we have already defined, just like I want to do the same with <c-w>
by using <space>w
, but there is a problem, if we remap directly to <c-w>
, the which-key window doesn't appear, and if we noremap= false
to <c-w>
, we need to wait for timeoutlen for the which-key window to appear, so we need a better way to reuse our previously set shortcuts or preset shortcuts
Describe the solution you'd like
When the key you want to set is already set in the which-key, use the previous setting directly, e.g. ["<leader>w"] = { "<C-W>", "+window" ,name=""}
should have the same effect as
Describe alternatives you've considered
add a function like
vim.g.WK_shown = false
wk.setup({
key_labels = { ["<leader>"] = "SPC" },
})
local function wk_alias(keys)
local timeout = vim.o.timeoutlen
if vim.g.WK_shown then
vim.o.timeoutlen = 0
end
local key_codes = vim.api.nvim_replace_termcodes(keys, true, false, true)
vim.api.nvim_feedkeys(key_codes, "m", false)
vim.defer_fn(function()
vim.o.timeoutlen = timeout
vim.g.WK_shown = false
end, 10)
end
vim.api.nvim_create_autocmd({ "Filetype" }, {
pattern = "WhichKey",
callback = function()
vim.g.WK_shown = true
end,
})
This way we can set <leader>w
as an alias for <c-w>
, which is what I'm doing now
["<leader>w"] = {
function()
wk_alias("<c-w>")
end,
"+window",
name = "",
},
Additional context
No response