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.38k stars 177 forks source link

bug: `presets.operators["d"] = nil` does not disable pending operators #502

Closed ColinKennedy closed 3 months ago

ColinKennedy commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.0

Operating system/version

CentOS Linux release 7.9.2009 (Core)

Describe the bug

I'd like whichkey not to pop up when pressing the d key. For the most part this works however some other installed plug-ins, https://github.com/tpope/vim-surround and https://github.com/tommcdo/vim-ninja-feet for example, extend d and other modes with o-pending operators and those completion results are still shown by which-key even though I've included require("which-key.plugins.presets").operators["d"] = nil on start-up.

Here's part of my configuration (full reproduction at the bottom)

Click to expand (Uses [lazy.nvim](https://github.com/folke/lazy.nvim)) ```lua -- Note: The full configuration truncated to only the relevant parts { "folke/which-key.nvim", event = "VeryLazy", config = function() local which_key = require("which-key") which_key.setup { triggers_blacklist = { c = {"%", ">"}, -- Prevent mappings like %s/ from popping up }, plugins = { presets = { motions = false, text_objects = false, operators = false, } } } local presets = require("which-key.plugins.presets") presets.operators["d"] = nil which_key.register( { [""] = { c = "+file-ish prefix", d = "+debug prefix", f = "[f]ind text using hop-mode", i = { name = "+insert prefix", d = "[i]nsert auto-[d]ocstring.", }, r = "+run prefix", s = { name = "+misc prefix", a = { "[s]plit [a]rgument list" }, }, }, [""] = { name = "Space Switching Mappings", A = "Show [A]rgs list", B = "Show [B]uffers list", E = "[E]dit a new project root file", L = "[L]ines searcher (current file)", S = { name = "[S]witcher aerial.nvim windows", A = "[S]witch [N]avigation", S = "[S]witch [S]idebar", }, W = "Open [W]orkspace (NvimTree)", Z = "[Z]oxide's interative pwd switcher", c = { name = "+LSP [c]ode prefix", a = "Run [c]ode [a]ction", }, e = "[e]dit a `:pwd` file", q = "Switch to [q]uickfix window, if open", w = { name = "+workspace LSP prefix", a = "LSP [w]orkspace [a]dd", l = "LSP [w]orkspace [l]ist", r = "LSP [w]orkspace [r]remove", }, }, } ) end, } { "tpope/vim-surround" } { "tommcdo/vim-ninja-feet" } ```

Steps To Reproduce

  1. Install which-key.nvim and tpope/vim-surround as normal, using your favorite package manager
  2. Load Neovim
  3. Press the d key

You should see output that looks like this:

Screenshot from 2023-08-20 13-12-39

Expected Behavior

No pop-up to show because

local presets = require("which-key.plugins.presets")
presets.operators["d"] = nil

was included in the which-key.nvim configuration

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",
  { "tommcdo/vim-ninja-feet" },
  { "tpope/vim-surround" },
  {
      "folke/which-key.nvim",
      event = "VeryLazy",
      config = function()
          local which_key = require("which-key")

          which_key.setup {
              triggers_blacklist = {
                  c = {"%", ">"},  -- Prevent mappings like %s/ from popping up
              },
              plugins = {
                  presets = {
                      motions = false,
                      text_objects = false,
                      operators = false,
                  }
              }
          }

          local presets = require("which-key.plugins.presets")
          presets.operators["d"] = nil
      end,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
MariaSolOs commented 1 year ago

@ColinKennedy the docs indicate that you should disable operators before calling setup (refer to the comment in the example of this section).

ColinKennedy commented 1 year ago

I'd like to confirm what you're suggesting. If you mean "move the presets.operators["d"] = nil before setup, that doesn't work. If you use the reproduction file and load the repro with nvim -u /path/to/repro.lua and press d, which-key will pop-up and show s ➜ <Plug>Dsurround

I tried a few configurations but none of them work

Modified Repro using nil ```lua -- 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", { "tommcdo/vim-ninja-feet" }, { "tpope/vim-surround" }, { "folke/which-key.nvim", event = "VeryLazy", config = function() local which_key = require("which-key") local presets = require("which-key.plugins.presets") presets.operators["d"] = nil which_key.setup { triggers_blacklist = { c = {"%", ">"}, -- Prevent mappings like %s/ from popping up }, plugins = { presets = { motions = false, text_objects = false, operators = false, } } } end, }, } require("lazy").setup(plugins, { root = root .. "/plugins", }) vim.cmd.colorscheme("tokyonight") -- add anything else here ```
Includes "operators = false", only ```lua -- 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", { "tommcdo/vim-ninja-feet" }, { "tpope/vim-surround" }, { "folke/which-key.nvim", event = "VeryLazy", config = function() local which_key = require("which-key") which_key.setup { plugins = { presets = { operators = false, } } } end, }, } require("lazy").setup(plugins, { root = root .. "/plugins", }) vim.cmd.colorscheme("tokyonight") -- add anything else here ```
Explicit plugin.operators = nil & empty setup call ```lua -- 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", { "tommcdo/vim-ninja-feet" }, { "tpope/vim-surround" }, { "folke/which-key.nvim", event = "VeryLazy", config = function() local which_key = require("which-key") local presets = require("which-key.plugins.presets") presets.operators["d"] = nil which_key.setup {} end, }, } require("lazy").setup(plugins, { root = root .. "/plugins", }) vim.cmd.colorscheme("tokyonight") -- add anything else here ```

None of the above work. I've tried more configurations that this but I hope this gets addressed. If you have an modified configuration that works, it'd be great if you can post it for me and any others who are experiencing this. Thank you.

MariaSolOs commented 1 year ago

@ColinKennedy I think you've misunderstood what the setting does. presets.operators will just disable the built-in Vim operators (and so as your picture clearly shows, which-key isn't showing things like dd, dw, etc). It won't disable the d motions coming from other plugins. In order to do that, you should use which_key_ignore or set ignore_missing.

ColinKennedy commented 1 year ago

It seems the best I can hope for with current functionality is ignore_missing as which_key_ignore doesn't prevent the pop-up from what I can tell. FWIW I knew that it was o-pending operators from other plug-ins that was why the pop-up was being shown, just not the setting needed to disable them. I was able to piece together using the bits you provided. It'd still be nice to be able to disable pop-ups for selective keys but this is good enough for me. Thanks.

MariaSolOs commented 1 year ago

@ColinKennedy glad I could help :)

github-actions[bot] commented 4 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.