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: any nested buffer keymaps remove higher depth descriptions #524

Closed miki725 closed 3 weeks ago

miki725 commented 10 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.9.1

Operating system/version

Arch Linux

Describe the bug

lets take a simple example:

vim.keymap.set("n", "<leader>q", "<space>", { desc = "test" })
vim.keymap.set("n", "<leader>qq", "<space>", { desc = "test2" })
vim.keymap.set("n", "<leader>qqq", "<space>", { desc = "test3" })

all levels render for me as:

note that descriptions of test, test2 are all displayed on all levels.

Now if any of the these keymaps are mapped to any buffer:

vim.keymap.set("n", "<leader>q", "<space>", { desc = "test" })
vim.keymap.set("n", "<leader>qq", "<space>", { desc = "test2" })
vim.keymap.set("n", "<leader>qqq", "<space>", { desc = "test3", buffer = 0 })

the descriptions for test and test2 dissapear and only the buffer-related descriptions are displayed:

Steps To Reproduce

add nested keymaps (same keys followed by more keys) and make one of them be linked to a buffer. for example:

vim.keymap.set("n", "<leader>q", "<space>", { desc = "test" })
vim.keymap.set("n", "<leader>qq", "<space>", { desc = "test2" })
vim.keymap.set("n", "<leader>qqq", "<space>", { desc = "test3", buffer = 0 })

Expected Behavior

all descriptions should show up in which-key menu

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", lazy = false },
    { "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.keymap.set("n", "<leader>q", "<space>", { desc = "test" })
vim.keymap.set("n", "<leader>qq", "<space>", { desc = "test2" })
vim.keymap.set("n", "<leader>qqq", "<space>", { desc = "test3", buffer = 0 })
phortonssf commented 4 months ago

I think this is a feature and not a bug. I use the buffer binding to have localleader key mapped to per filtetype whichkey menus for different contexts, like fugitive, logs etc. This removes all the general mappings as the bug suggested, but keeps the specific mappings when used in the ftplugin.

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.