which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

Key aliases

Open cyruseuros opened this issue 3 years ago • 3 comments

If keys are aliased to each other (e.g. wk.register('<leader>w', '<c-w>')), which-key should reuse mappings automatically.

Thank you for an amazing plugin!

cyruseuros avatar Sep 02 '21 04:09 cyruseuros

Same here trying to achieve the same, I'm trying to not duplicate the existing keybindings for <C-w>

gomezhyuuga avatar Nov 24 '21 10:11 gomezhyuuga

w = { "<c-w>", "<C-W>", noremap = false },

Same problem, I'm using this now, but this still has the problem of having to wait a while for the prompt to appear, is there a better way to do this?

st0nie avatar Apr 05 '23 11:04 st0nie

Same here trying to achieve the same, I'm trying to not duplicate the existing keybindings for <C-w>

vim.g.WK_shown = false


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)
	local timer = vim.loop.new_timer()
	if timer == nil then
		return nil
	end
	timer:start(
		5,
		0,
		vim.schedule_wrap(function()
			vim.o.timeoutlen = timeout
			vim.g.WK_shown = false
		end)
	)
end

vim.api.nvim_create_autocmd({ "Filetype" }, {
	pattern = "WhichKey",
	callback = function()
		vim.g.WK_shown = true
	end,
})

wk.register({
...
		w = {
			function()
				wk_alias("<c-w>")
			end,
			"+window",
			name = "",
		},
...
})

I found the almost perfect solution

st0nie avatar Apr 06 '23 02:04 st0nie