Skip to content

bug: which-key menu not showing up for <localleader> mappings #476

@Subjective

Description

@Subjective

Did you check docs and existing issues?

  • I have read all the which-key.nvim docs
  • I have searched the existing issues of which-key.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.0-dev-646+gc4df2f08b

Operating system/version

MacOS 13.4

Describe the bug

Hitting the <localleader> key doesn't trigger the which-key menu for buffer local mappings involving the <localleader> key. Interestingly enough, it loads properly after loading the which-key menu for <leader> in the same buffer prior to pressing <localleader>. This is primarily an issue with plugins like spectre, vimtex, diffview, etc. which set keybindings for a specific plugin related filetype.

Btw, this is a duplicate of #172 (sorry), but I noticed that it still seems to be around so I thought I might bring it up again. The workaround suggested in that issue works, but is rather cumbersome:

vim.api.nvim_create_autocmd("FileType", {
  desc = "Set up Spectre Which-Key descriptions",
  group = vim.api.nvim_create_augroup("spectre_mapping_descriptions", { clear = true }),
  pattern = "spectre_panel",
  callback = function()
    vim.keymap.set("n", "<localleader>", function() require("which-key").show "," end, { buffer = true })
  end,
})

Steps To Reproduce

  1. Enter a buffer with buffer local mappings (in the provided config, :Spectre or hit <leader>s
  2. Hit the localleader key
  3. Which-key menu doesn't show up

Expected Behavior

I would expect the which-key menu to display for localleader mappings in a specific buffer.

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)

vim.g.mapleader = " "
vim.g.maplocalleader = ","

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	{ "folke/which-key.nvim", opts = {} },
	{
		"nvim-pack/nvim-spectre",
		cmd = "Spectre",
		dependencies = "nvim-lua/plenary.nvim",
		init = function()
			local wk = require "which-key"
		end,
		opts = function()
			local prefix = "<localleader>"

			return {
				open_cmd = "new",
				mapping = {
					send_to_qf = { map = prefix .. "q" },
					replace_cmd = { map = prefix .. "c" },
					show_option_menu = { map = prefix .. "o" },
					run_current_replace = { map = prefix .. "r" },
					run_replace = { map = prefix .. "R" },
					change_view_mode = { map = prefix .. "v" },
					resume_last_search = { map = prefix .. "l" },
				},
			}
		end,
		keys = { { "<leader>s", function() require("spectre").open() end, desc = "Spectre", }, },
	},
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleThis issue or PR has been inactive for a while

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions