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
4.99k stars 160 forks source link

bug: Mappings using multiple backslashes cause :WhichKey to crash #543

Closed strokirk closed 3 weeks ago

strokirk commented 8 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0-dev-1338+gebe489d8f

Operating system/version

MacOS 14.1.1 (23B81)

Describe the bug

The \ key seems to cause some issues with which-key, which causes incompatibility with some other plugins that use it for default mappings.

Note that this only happens if the cpoption="B" is not present, making this a fairly niche bug.

Steps To Reproduce

  1. Add a mapping using multiple \ characters, e.g.: nnoremap \\a gs
  2. Run :WhichKey, and the following crash ensues:
E5108: Error executing lua ...al/share/nvim/lazy/which-key.nvim/lua/which-key/util.lua:130: {
  internal = { "a" },
  keystr = "\\a",
  notation = { "\\", "a" }
}
stack traceback:
        [C]: in function 'error'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/util.lua:130: in function 'parse_keys'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/keys.lua:425: in function 'update_keymaps'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/keys.lua:333: in function 'update'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/init.lua:47: in function 'show'
        ...al/share/nvim/lazy/which-key.nvim/lua/which-key/init.lua:63: in function 'show_command'
        [string ":lua"]:1: in main chunk

Expected Behavior

No crash.

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
vim.o.cpoptions = ""
vim.cmd[[nnoremap \\a gs]]
github-actions[bot] commented 1 month 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.