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
5.42k stars 176 forks source link

bug: Starting in 3.8.0 I can't get <leader> to work as a trigger #766

Closed bhutch29 closed 3 months ago

bhutch29 commented 3 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

3.8.0

Operating system/version

Linux 6.9.9

Describe the bug

Starting in 3.8.0, no matter what trigger configuration or keymap configuration I try, I can't get to trigger WhichKey. 3.9.0 and 3.10.0 do not work either.

If I run :WhichKey manually and then press it works as expected.

I apologize, I am having a really hard time producing a repro.lua that works at all, so I did not include one here. I will keep trying.

Steps To Reproduce

  1. Launch nvim w/ which-key and either trigger or explicit trigger set, plus at least one -prefixed keybinding defined.
  2. Press

Expected Behavior

WhichKey should open, it does not.

Health

which-key: require("which-key.health").check()

- OK Most of these checks are for informational purposes only.
  WARNINGS should be treated as a warning, and don't necessarily indicate a problem with your config.
  Please |DON't| report these warnings as an issue.

Checking your config ~
- WARNING |mini.icons| is not installed
- WARNING |nvim-web-devicons| is not installed
- WARNING Keymap icon support will be limited.

Checking for issues with your mappings ~
- OK No issues reported

checking for overlapping keymaps ~
- WARNING In mode `n`, <gc> overlaps with <gcA>, <gco>, <gcO>, <gcc>:
  - <gc>: Toggle comment
  - <gcA>: Comment insert end of line
  - <gco>: Comment insert below
  - <gcO>: Comment insert above
  - <gcc>: Toggle comment line
- WARNING In mode `n`, <gb> overlaps with <gbc>:
  - <gb>: Comment toggle blockwise
  - <gbc>: Comment toggle current block
- WARNING In mode `n`, <<Space>;> overlaps with <<Space>;;>:
  - <<Space>;>: comment
  - <<Space>;;>: line comment
- OK Overlapping keymaps are only reported for informational purposes.
  This doesn't necessarily mean there is a problem with your config.

Checking for duplicate mappings ~
- OK No duplicate mappings found

Log

Debug Started for v3.8.0
  new Mode(n:1)
  Trigger(add) Mode(n:1) ` ' " g` g' z= <C-W> g <Plug> , z <Space> ] [
  BufNew(3)
  BufNew(4)
  on_key: <Space><Space>
  BufNew(5)
  BufNew(6)
  BufNew(7)
  BufNew(8)
  BufEnter(7)
    new Mode(n:7)
  ModeChanged(n:i)
    new Mode(i:7)
    Unsafe(pending "<80>")
    suspend: Mode(i:7)
  Trigger(add) Mode(i:7) <C-R>
  Trigger(add) Mode(n:7) ` ' " z= g` g' <Plug> ] z <C-W> <Space> g [
  on_key: <Esc>
  ModeChanged(i:n)
    Safe(true)
  on_key: <Esc>
  BufEnter(1)
  on_key: :
  ModeChanged(n:c)
    new Mode(c:1)
    Safe(true)
  BufNew(9)
  BufNew(10)
  Trigger(add) Mode(c:1) <C-R>
  on_key: p
  on_key: w
  on_key: d
  on_key: <CR>
  ModeChanged(c:n)
    Unsafe(command-mode)
    suspend: Mode(n:1)
    Trigger(del) Mode(n:1) ` " g` g' z= <C-W> g <Plug> , z ] [ '
  Trigger(add) Mode(n:1) ` ' " g` g' z= <C-W> g <Plug> , z <Space> ] [
  BufNew(11)

Repro

No response

max397574 commented 3 months ago

works with my config. so it's likely an issue with your config and you should try to provide a minimal repro. Look at other issues for examples

bhutch29 commented 3 months ago

works with my config. so it's likely an issue with your config and you should try to provide a minimal repro. Look at other issues for examples

I will keep trying. But my full config works great in versions 3.7.0 and below. And I have tried a large number of permutations of my config. So something must have changed in 3.8.0 in the expectations of the config that I still do not understand. Again, will keep trying!

bhutch29 commented 3 months ago

Ahah, ok, I found the culprit.

For reasons that currently escape me, I have the following early in my config:

vim.keymap.set("n", " ", "<NOP>", {})
vim.keymap.set("v", " ", "<NOP>", {})

Removing this fixes everything.

max397574 commented 3 months ago

as someone pointed out some people might have those mappings because they don't want the cursor to move if they're to slow with pressing second keys with leaderkey space but this should've been fixed on a recent version

bhutch29 commented 3 months ago

That sounds good. If it doesn't seem like a bug, just an out-of-place config option that needs removing, then please close this issue. Btw, I am a very happy user of this plugin, thanks to everyone involved!

max397574 commented 3 months ago

Imo it is a bug because this was an issue before and a fix was added for it but apparently this didn't cover all the cases

folke commented 3 months ago

Something is indeed broken with my fix for those <nop> mappings. Will check

folke commented 3 months ago

Although, no it does work for me with those <nop> mappings. @bhutch29 are you 100% sure you were using the lastest version?

ulisses-cruz commented 3 months ago

I'm having the same issue with the keymap:

vim.api..nvim_set_keymap('n', '<space>', '<nop>', { noremap = true, silent = true })
folke commented 3 months ago

@ulisses-cruz are you using the latest version? Op was using 3.8.0 which did not include the fix. You need to be on the latest version.

ulisses-cruz commented 3 months ago

@folke I do have the last changes as of today: image

folke commented 3 months ago

Turns out that <nop> isn't an actual virtual key in Neovim so it never got normalized to something like <Nop>.

Just added special handling for <Nop> in any case.

ulisses-cruz commented 3 months ago

Thanks @folke. It works for me now. And thanks for the very very fast response.

bhutch29 commented 3 months ago

Fix is working great, thanks so much!