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

feat(keys): desc in <nop> keymaps can now become prefix label #522

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

pk-kampanart
Copy link
Contributor

@pk-kampanart pk-kampanart commented Sep 22, 2023

  • User can now use keymaps with to set desc as label to prefix
    key

  • Fix some typo

Example:

...
map("n", "<leader>h", "<Nop>", {desc = "Help Prefix"})
map("n", "<leader>p", "<Nop>", {desc = "Projects Prefix"})
map("n", "<leader>f", "<Nop>", {desc = "File Prefix"})
map("n", "<leader>b", "<Nop>", {desc = "Buffer Prefix"})
map("n", "<leader>c", "<Nop>", {desc = "Coding Prefix"})
map("n", "<leader>g", "<Nop>", {desc = "Git Prefix"})
map("n", "<leader>d", "<Nop>", {desc = "Diagnostic Prefix"})
map("n", "<leader>t", "<Nop>", {desc = "Toggle & Setting Prefix"})
...

test

@pk-kampanart pk-kampanart marked this pull request as ready for review September 22, 2023 22:54
* User can now use keymaps with <nop> to set `desc` as label to prefix
  key

* Fix some typo
@folke
Copy link
Owner

folke commented Jun 6, 2024

This is actually really cool. Was just looking to implement something similar :)

fyi: It also works with an empty mapping like

map("n", "<leader>h", "", {desc = "Help Prefix"})

@folke folke merged commit c1958e2 into folke:main Jun 6, 2024
3 checks passed
@folke
Copy link
Owner

folke commented Jun 6, 2024

Thanks!

@bluss
Copy link

bluss commented Jun 6, 2024

Trying to set up a prefix like this (with updated which-key (c1958e2) and lazy.nvim (0c1ec52)). Using the keys table in lazy.nvim config:

    {"<leader>t", "<nop>", mode = "n", desc = "+terminal" },
    {"<leader>tf", "<cmd>ToggleTerm direction=float<cr>", mode = "n", desc = "Toggleterm float"},

Which-key doesn't toggle for this key mapping (if it's typed fast enough), which is a drawback. I would wish for a UX where <leader>t will open which-key and wait for the real kemap (<leader>tf for toggleterm float etc.)

@folke
Copy link
Owner

folke commented Jun 6, 2024

@bluss can you update both which-key and lazy?

@bluss
Copy link

bluss commented Jun 6, 2024

updated both. Fwiw, the behaviour is still the same (before and after lazy load too); typing <leader>t quick enough is just a nop and doesn't open which-key. Don't know if that's expected. Neovim v0.10.0

@folke
Copy link
Owner

folke commented Jun 6, 2024

which-key indeed has to have run at least once, otherwise your nop keymap would be executed.
You can still use register like before. That still works.

@bluss
Copy link

bluss commented Jun 6, 2024

Got it, thank you!

@folke
Copy link
Owner

folke commented Jun 6, 2024

There was indeed something wrong there and should now be fixed!

ccf0276

@bluss
Copy link

bluss commented Jun 11, 2024

Thank you @folke. It works like I would prefer now (which-key 0099511, lazy eb49574). This case still is a minor fail: In that configuration above, if <leader>tf is pressed fast enough (no which-key trigger) then any <leader>t after that does not trigger which-key to open.

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

Successfully merging this pull request may close these issues.

None yet

3 participants