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: Number gets inserted if used with motion and c if exited with keymapped escape #770

Closed KodyVB closed 1 month ago

KodyVB commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

Arch Linux 6.9.10-arch1-1

Describe the bug

If you want to change 3 letters and use c3l or change two paragraphs and use c2}, etc., whatever number you used to describe the motion gets pasted into the text if you exit normal mode with a remapped escape.

Steps To Reproduce

  1. Write some text or open a file with text to change
  2. Use c with a numbered motion, i.e. c10l
  3. Exit insert mode via the escape sequence (which is ;j using the config below)

Expected Behavior

It should just enter normal mode, like if you press <esc> itself. I tested this with which-key uninstalled, and the problem went away with the plugin not being used.

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 <gcc>:
  - <gc>: Toggle comment
  - <gcc>: Toggle comment line
- 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.10.0
new Mode(n:1)
Trigger(add) Mode(n:1) ' " ` z= g` g' z g [ ; ] <C-W>
on_key: i
ModeChanged(n:i)
  new Mode(i:1)
  Safe(true)
Trigger(add) Mode(i:1) <C-R> ;
on_key: f
on_key: d
on_key: a
on_key: s
on_key: f
on_key: d
on_key: s
on_key: a
on_key: f
on_key: d
on_key: a
on_key: s
on_key: f
on_key: a
on_key: s
on_key: d
on_key: <Esc>
ModeChanged(i:n)
  Safe(true)
on_key: h
on_key: h
on_key: h
on_key: h
on_key: h
on_key: h
on_key: h
on_key: h
on_key: c
ModeChanged(n:no)
  new Mode(o:1)
  Safe(true)
  State(start): Mode(o:0) Node() { defer = false }
    update Mode(o:1)
    continue:  Mode(o:1)
    getchar
    Trigger(add) Mode(o:1) [ g ]
    on_key: 3
    got: 3
    suspend: Mode(o:1)
    Trigger(del) Mode(o:1) [ g ]
    feedkeys: Mode(o:1) 3
on_key: 3
on_key: 2
on_key: l
ModeChanged(no:i)
  Safe(true)
Trigger(add) Mode(o:1) [ g ]
on_key: a
on_key: ;
State(start): Mode(i:0) Node(;) { keys = ";" }
  update Mode(i:1)
  continue: ; Mode(i:1)
  getchar
  on_key: j
  got: j
  suspend: Mode(i:1)
  Trigger(del) Mode(i:1) ; <C-R>
  feedkeys: Mode(i:1) 32;j
on_key: 3
on_key: 2
on_key: ;j
ModeChanged(i:n)
  Safe(true)
Trigger(add) Mode(i:1) <C-R> ;
on_key: :
ModeChanged(n:c)
  new Mode(c:1)
  Safe(true)
Trigger(add) Mode(c:1) <C-R>
on_key: q
on_key: !
on_key: <CR>
ModeChanged(c:n)
  Unsafe(command-mode)
  suspend: Mode(n:1)
  Trigger(del) Mode(n:1) ' " ` z= g` g' g [ ; ] <C-W> z
Trigger(add) Mode(n:1) ' " ` z= g` g' z g [ ; ] <C-W>

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 = {} },
    -- add any other plugins here
  },
})
vim.api.nvim_set_var("mapleader", ";")
vim.keymap.set({ "n", "v", "i" }, "<Leader>j", "<Esc>", {})