folke / which-key.nvim

💥 Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type.
Apache License 2.0
4.86k stars 157 forks source link

Key aliases #160

Closed cyruseuros closed 4 days ago

cyruseuros commented 2 years ago

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!

gomezhyuuga commented 2 years ago

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

st0nie commented 1 year ago
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 commented 1 year ago

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

github-actions[bot] commented 1 week ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

haoming-li-ling commented 3 days ago

@folke, this issue is closed? does that mean for remappings like this, which-key works out of the box? that is not the behavior I can see, though.

folke commented 3 days ago

nmap <leader>w <c-w> for example works