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.25k stars 165 forks source link

bug: macro execution with :normal @x #596

Closed pteroctopus closed 2 months ago

pteroctopus commented 5 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.5

Operating system/version

Ubuntu 22.04

Describe the bug

When macro is executed in command mode with :normal @x and macro contains entering a command in command mode where ^R will be used to get content of the register: neovim will freeze. If Ctrl+C is pressed the following error message will be printed:

E5108: Error executing lua Keyboard interrupt
stack traceback:
        [C]: in function 'getchar'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:96: in function 'read_pending'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:281: in function 'on_keys'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/view.lua:255: in function 'open'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/init.lua:49: in function 'show'
        [string ":lua"]:1: in main chunk

More details in reproduction steps.

Steps To Reproduce

  1. Create a file reproduce.txt with: touch reproduce.txt
  2. Open file with neovim: nvim reproduce.txt
  3. In file write two lines with content: this will be replaced with content of register i
  4. Record folowing macro on first line. Use register x: :.s/this/^Ri/g (This macro will replace all words this on current line with content of register i)
  5. Execute macro in command mode with: :normal @x
  6. Neovim will freeze
  7. Press Ctrl+c to get error written in description

If the same steps are done in neovim instance without WhichKey plugin problem will not happen.

screenshot-2024-04-15_20-19_1

Expected Behavior

Neovim using WhichKey plugin should not freeze and error should not happen when macro is executed with :normal @x when macro uses retrieval of content of register in command mode.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/which-key.nvim", config = true },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
github-actions[bot] commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

pteroctopus commented 2 months ago

Not stale

folke commented 2 months ago

This is fixed in v3 https://github.com/folke/which-key.nvim/pull/624

Ready soon

pteroctopus commented 2 months ago

Thank you. Confirming that the problem is fixed.