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.18k stars 163 forks source link

Alt bingings on osx crash for nvim 0.7 #274

Closed D00mch closed 2 years ago

D00mch commented 2 years ago

https://user-images.githubusercontent.com/14236531/166142345-90d30589-1dc8-46df-b032-e9d95c0d1a97.mov

I used to be able to type alt+\<key> in the insert mode and writy symboles liek: ®, å, ß (for alt+\<r, a, s> respectively).

My use case was to type this keys in insert mode, copy the symbol and map it like:

"for alt+s.
noremap ß :w<CR>

Now, whenever I type alt+\<key> in the insert mode ("alt+s", for example), I see my cursor at the command line, all keys are ignoreed, and the only way to exit from it is to type , after that I see lots of noncense symbols inserted: åååååååååååååååååa....

petertriho commented 2 years ago

I have the same issue on neovim nightly + following master. Do not have the issue on neovim 0.7. There has been a lot of keymap changes over the last 2 days so I'm guessing that's what's causing the issue.

jemag commented 2 years ago

I had a similar issue (same error thrown) happen following neovim master where pressing <c-w> + another key (default vim keybinds) would not work anymore and throw that error. Did not modify my config at all beside updating plugins and neovim.

In my case, I had to now put the window preset to false otherwise it wouldn't let me use <c-w> anymore: so changed

    presets = {
...
      windows = true, -- default bindings on <c-w>
...
    },

to

    presets = {
...
      windows = false, -- default bindings on <c-w>
...
    },
zeertzjq commented 2 years ago

which-key.nvim is passing internal keycodes (the string returned by nvim_replace_termcodes()) to nvim_set_keymap(), which is not guaranteed to work.

jemag commented 2 years ago

@zeertzjq any idea why this seem to have started happening recently? Could it perhaps be linked to some of the changes on how neovim now handles simplifiable keys?

zeertzjq commented 2 years ago

Yes. Now unmapping <C-W> will not remove a mapping whose lhs is vim.api.nvim_replace_termcodes('<C-W>', true, true, true). Therefore which-key.nvim fails to remove the hooks it created. Before this change which-key.nvim didn't have a problem with keys with a Ctrl modifier, but already had a problem with keys with an Alt modifier or special keys. For example, pressing <F2> doesn't trigger which-key with the following mappings:

  ['<F2>'] = {
    a = {'<Nop>', ''},
    b = {'<Nop>', ''},
  },

In this case, which-key.nvim just creates the wrong hooks, so it doesn't work at all instead of hanging. Now this problem has extended to keys with a Ctrl modifier, and in this case creating the hooks succeeds, but removing the hooks fails.

jemag commented 2 years ago

thanks for the great explanation, saw bfredl PR and then yours, thought it might have something to do with it

zeertzjq commented 2 years ago

275 seems to fix the problem with Ctrl modifier. I can't test if it fixes the problem with Alt described in the top two comments because I cannot understand the issue description.

D00mch commented 2 years ago

I checked it and it doesn't fix the alt-problem. I changed description a little bit. The problem is that pressing alt+"any key" in insert mode steals the focus and result with the error and insertions of lot's of symbols like in the video in the description.