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

bug: v3 has problems with vim-sandwich #672

Closed ir-ae closed 1 month ago

ir-ae commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713484068

Operating system/version

Windows 10

Describe the bug

Which-key displays and waits for another key press after executing vim-sandwhich surround motions such as ds(, ds{ It only shows for yS, S, ys and cs if you dont type the whole command before the which-key delay but it shows regardless of typing speed for ds

Steps To Reproduce

  1. nvim -u repro.lua
  2. type (word)
  3. position cursor inside parentheses
  4. in normal mode: ds(

Expected Behavior

Do not display which-key after completed vim-sandwich keymap

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.
- 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 <gcc>:
  - <gc>: Toggle comment
  - <gcc>: Toggle comment line
- WARNING In mode `n`, <cs> overlaps with <css>:

- WARNING In mode `n`, <ys> overlaps with <yss>:

- WARNING In mode `n`, <ds> overlaps with <dss>:

- 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.2.0
on_key: i
ModeChanged(n:i)
on_key: w
on_key: o
on_key: r
on_key: d
on_key: <Esc>
ModeChanged(i:n)
on_key: yss
ModeChanged(n:c)
ModeChanged(c:n)
ModeChanged(n:no)
ModeChanged(no:c)
ModeChanged(c:no)
State(start): { "Mode(o)", "Node()", { update = true } }
  getchar
  on_key: (
  got: (
  reattach: { "", "o" }
  feedkeys: { "Mode(o)", "(" }
ModeChanged(no:n)
ModeChanged(n:v)
on_key: (
ModeChanged(v:n)
on_key: ds
ModeChanged(n:c)
ModeChanged(c:n)
ModeChanged(n:no)
on_key: (
ModeChanged(no:c)
ModeChanged(c:no)
State(start): { "Mode(o)", "Node()", { update = true } }
  getchar
  on_key: <Esc>
  got: <Esc>
ModeChanged(no:n)
ModeChanged(n:v)
on_key: :
ModeChanged(n:c)
on_key: q
on_key: !
on_key: <CR>
ModeChanged(c:n)

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/which-key.nvim", opts = {} },
    {"machakann/vim-sandwich",
      init = function ()
        vim.g["operator_sandwich_no_default_key_mappings"] = 1
      end,
      config = function ()
        vim.cmd "runtime macros/sandwich/keymap/surround.vim"
      end
    }
  },
})
roycrippen4 commented 1 month ago

I'm having a similar issue with nvim-surround. The previous version would display options for surround's keys like ys and ds. Wk doesn't display anything for nvim-surround now. Also, in the previous version "native" operations like dw would execute instantly. In v3, operator pending keys like dw, cw, and ciw don't execute instantly, it pauses and shows many options.

folke commented 1 month ago

@roycrippen4 that is not related to this issue and I can't reproduce that. If you want me to look at it, submit an issue with a working repro.

folke commented 1 month ago

Should be fixed now.

Note that typing d first and then waiting to press s later won't work. That might have worked with which-key before, but no longer works as this was incorrect.

vim-sandwish doesn't seem to define an omap for s, and only has a normal mode ds mapping.

When you press d you enter operator pending mode so only omaps work at that point.

echasnovski commented 1 month ago

vim-sandwish doesn't seem to define an omap for s, and only has a normal mode ds mapping.

When you press d you enter operator pending mode so only omaps work at that point.

In which-key-less Neovim it enters Operator-pending only after it is sure that only d is pressed. So making a ds Normal mode mapping is enough. Moreover, I don't think creating s Operator-pending mode mapping is a correct way to make ds work as operator (at least because it will be present for every operator, which is not intended).

This might be related to echasnovski/mini.nvim#1058.

folke commented 1 month ago

This is unrelated to which key though. D or ds doesn't trigger any which key keymaps, so timeoutlen works as normal for those mappongs

echasnovski commented 1 month ago

Yeah, I've just tried to reproduce the echasnovski/mini.nvim#1058 with 'which-key.nvim' and it seems to work as I'd expect. The core description of the issue is "before, s will show which-key and wait for next action (add, delete ...) but now it just uses nvims default s action( replacing current char going into insert mode).", however I could not reproduce this even before v3.

yavorski commented 1 month ago

So as a user, I'm wondering if which-key is supposed to work with mini.surround default keybindings somehow with or without additional configuration? Specifically for the initial key bindings when you press only s -> sa, sd, sr etc... I have also disabled s key:

vim.keymap.set({ "n", "x" }, "s", "<Nop>")
folke commented 1 month ago

If you press only s, then Neovim's s keybinding will be executed. mini.surround only maps sa and others, not the bare s mapping.

Old which-key messed up the normal NEovim behavior in this case. v3 does it how it should.

If you want to show which-key on s, you can add a keymap for s to WhichKey n s

yavorski commented 1 month ago

Awesome! Thanks a lot! I finally got it to work 👍

ir-ae commented 1 month ago

I'm having the same problem as I had with ds when trying to change or delete text with c/{pattern}<cr> or d/{pattern}<cr>. Should I open another issue for that?

folke commented 1 month ago

Which-key config has changed (again). The new way to achieve what op wants on s would be:

triggers = {
    { "<auto>", mode = "nixsotc" },
    { "s", mode = { "n", "v" } },
}

See Triggers for more information