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: `require("which-key")` breaks dot repeat actions #636

Closed henderj closed 1 month ago

henderj commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0 commit 27fb629

Operating system/version

WSL2 Ubuntu 22.04.4 LTS (on Windows 11, Version 10.0.22631 Build 22631)

Describe the bug

Calling require("which-key") causes the dot repeat action to not work. For example, using cw to change a word, then using . over another word puts the characters in the wrong places and sometimes leaves neovim in insert mode.

I use lazy.nvim, and this bug happens with the following which-key configurations:

{ "folke/which-key.nvim", opts = {} }
{ "folke/which-key.nvim", config = true }
{ "folke/which-key.nvim", config = function() require("which-key") end }

However, this bug does not happen with the following which-key configurations:

{ "folke/which-key.nvim" }

{ "folke/which-key.nvim", config = function() end }

Steps To Reproduce

  1. Use the minimal init.lua
  2. Insert the following text
    hey hey
  3. Cursor over second 'e', use ciw, now, <esc>.
    hey now
  4. Put cursor over first 'e', use .
    hwey now
  5. Cursor is still in insert mode.

Expected Behavior

Following the above example, I would expect the . action to change the first hey into now.

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", opts = {} },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")