Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/feature: partial mapping (aliases) don't work as expected #583

Open
1 task done
MattSturgeon opened this issue Mar 5, 2024 · 2 comments
Open
1 task done

bug/feature: partial mapping (aliases) don't work as expected #583

MattSturgeon opened this issue Mar 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@MattSturgeon
Copy link

Did you check the docs?

  • I have read all the which-key.nvim docs

Is your feature request related to a problem? Please describe.

When I map "<leader>w" to "<C-w>", I don't get the which-key popup for <C-w> when typing <leader>w.

  • If I type <C-w> manually, the "wondow" mappings are displayed.
  • If I type <leader>w, C^W is shown in the status bar, however which-key's window does not appear.

Describe the solution you'd like

"Alias" mappings should be detected by which-key and displayed

Describe alternatives you've considered

Alternatively, "aliases" could be manually configured during plugin setup.

e.g.

operators = { --[[ ... ]] },
key_labels = { --[[ ... ]] },
key_aliases = {
  ["<C-w>"] = { "<leader>w", "gw" },
},

Additional context

Extra ideas:

  • Sibling aliases could be grouped together
  • All known aliases could be listed next to mappings
  • Aliases could inherit the base-key's description when the alias doesn't have one
@MattSturgeon MattSturgeon added the enhancement New feature or request label Mar 5, 2024
MattSturgeon added a commit to MattSturgeon/nix-config that referenced this issue Mar 5, 2024
Rather than doing `Ctrl`+Key, map `<leader>w` to `<C-w>`.

Unfortunately this is affected by folke/which-key.nvim#583
@adrianchongseek
Copy link

You can try something like this:

return {
  'folke/which-key.nvim',
  config = function()
    local wk = require('which-key')
    wk.register({
      ["<leader>"] = {
        w = {
          '<cmd>WhichKey <C-w><cr>', 'Window actions'
        },
      },
      ["gw"] = {
        '<cmd>WhichKey <C-w><cr>', 'Window actions'
      }
    })
  end
}

This is not perfect, but it will work like you expect.

MattSturgeon added a commit to MattSturgeon/nix-config that referenced this issue Mar 6, 2024
Until [#583] is resolved, we need to call `:WhichKey` manually.

Luckily the `<C-w>` mapping is delegated to which-key so it's not a big
deal...

[#583]: folke/which-key.nvim#583

Co-authored-by: Adrian Chong <adrianchong@seekasia.com>
@MattSturgeon
Copy link
Author

MattSturgeon commented Mar 6, 2024

You can try something like this: ``["w"] = { 'WhichKey ', 'Window actions' }`

This is not perfect, but it will work like you expect.

Thanks, calling :WhichKey [[action]] manually is a decent workaround, other than which-key opening instantly (without any delay) it seems to achieve what I wanted.

I'll leave this issue open so that @folke can consider the underlying issue, feature request and/or adding the workaround example to the docs (etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants