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

Disable visual mappings #26

Closed NTBBloodbath closed 3 years ago

NTBBloodbath commented 3 years ago

Is there a way to stop triggering WhichKey at v key mappings? I'm trying to enter visual mode without triggering it but it isn't possible

Already tried with

wk.register({['v'] = 'which_key_ignore'})

but the key bindings keep coming out when pressing v :confused:

klooj commented 3 years ago

you need to specify a mode. i think that should fix it.

so wk.register({['v'] = 'which_key_ignore'}, {mode = 'n'}) and wk.register({['v'] = 'which_key_ignore'}, {mode = 'v'})

klooj commented 3 years ago

nevermind. i'm getting this error after timeoutlen if i just press v once in normal mode:

image
NTBBloodbath commented 3 years ago

Strange, I just placed it and it didn't give errors, however instead of showing +Visual Character Mode, it shows +which_key_ignore :thinking:

Maybe it's not possible to disable triggering WhichKey in visual mode (for now), although it's not something that is very annoying

Screenshot_20210429_194419

folke commented 3 years ago

The correct way to disable this would be to not load the operators preset and configure operators manually:

{
  plugins = {
    -- ...
    presets = {
      operators = false
      -- ..
    },
  },
  -- add operators that will trigger motion and text object completion
  -- to enable all native operators, set the preset / operators plugin above
  operators = {
    d = "Delete",
    c = "Change",
    y = "Yank (copy)",
    ["g~"] = "Toggle case",
    ["gu"] = "Lowercase",
    ["gU"] = "Uppercase",
    [">"] = "Indent right",
    ["<lt>"] = "Indent left",
    ["zf"] = "Create fold",
    ["!"] = "Filter though external program",
    -- ["v"] = "Visual Character Mode",
    gc = "Comments"
 },
}

Although, this seems a bit verbose to just disable one operator. I'll see if I can come up with an easier way to do this.

NTBBloodbath commented 3 years ago

Thank you very much, it works great :smiley:

Should I close the issue or will it be closed when making changes?

folke commented 3 years ago

I think I'll just add some proper documentation on how to set up operators, motions and text objects and how the preset works in regards to that. You can leave it open for now :)

NTBBloodbath commented 3 years ago

Understood, thank you very much again :slightly_smiling_face:

joeynguyen commented 5 months ago

Although, this seems a bit verbose to just disable one operator. I'll see if I can come up with an easier way to do this.

For anyone still following this issue or views it in the future, this plugin's author, folke, did document how to do this in the README.

How to disable some operators? (like v)

-- make sure to run this code before calling setup()
-- refer to the full lists at https://github.com/folke/which-key.nvim/blob/main/lua/which-key/plugins/presets/init.lua
local presets = require("which-key.plugins.presets")
presets.operators["v"] = nil

I tried it and it works for me.

superatomic commented 3 months ago

Update: @joeynguyen's method doesn't work anymore on the latest version of which-key. Instead, add the following to which-key's options in the call to setup() (or in opts = { ... }, if using lazy):

defer = function(ctx)
  return ctx.mode == "v" or ctx.mode == "V" or ctx.mode == "<C-V>"
end,