which-key.nvim icon indicating copy to clipboard operation
which-key.nvim copied to clipboard

blacklist ignored

Open jemag opened this issue 3 years ago • 4 comments

Forgive me if my understanding of the blacklist concept is wrong, but given the following blacklist:

triggers_blacklist = {
    -- list of mode / prefixes that should never be hooked by WhichKey
    -- this is mostly relevant for key maps that start with a native binding
    -- most people should not need to change this
    i = { "j", "k" },
    v = { "j", "k" },
  },

I would expect that pressing j or k in insert or visual mode will not trigger which-key.

My use case is to not trigger which-key on "y" or "c"


To reproduce behavior

Use following minimal config

test.vim

set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')
Plug 'nvim-lua/plenary.nvim'
Plug 'tpope/vim-surround'
Plug 'folke/which-key.nvim'
Plug 'tpope/vim-fugitive'
call plug#end()

autocmd VimEnter * PlugClean! | PlugUpdate --sync | close
let mapleader = "\<Space>"
let maplocalleader = '-'
set timeoutlen=500
set mouse=a
" " Copy to clipboard
vnoremap  <leader>y  "+y
nnoremap  <leader>Y  "+yg_
nnoremap  <leader>y  "+y
nnoremap  <leader>yy  "+yy
nnoremap <silent> <leader>o :<C-u>call append(line("."),   repeat([""], v:count1))<CR>
nnoremap <silent> <leader>O :<C-u>call append(line(".")-1, repeat([""], v:count1))<CR>
nnoremap Y y$

lua << EOF
print("inside lua EOF")

require("which-key").setup{
  plugins = {
    marks = false, -- shows a list of your marks on ' and `
    registers = false, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
    -- the presets plugin, adds help for a bunch of default keybindings in Neovim
    -- No actual key bindings are created
    spelling = {
      enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
      suggestions = 20, -- how many suggestions should be shown in the list?
    },
    presets = {
      operators = false, -- adds help for operators like d, y, ... and registers them for motion / text object completion
      motions = false, -- adds help for motions
      text_objects = false, -- help for text objects triggered after entering an operator
      windows = true, -- default bindings on <c-w>
      nav = true, -- misc bindings to work with windows
      z = true, -- bindings for folds, spelling and others prefixed with z
      g = true, -- bindings for prefixed with g
    },
  },
  -- add operators that will trigger motion and text object completion
  -- to enable all native operators, set the preset / operators plugin above
  icons = {
    breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
    separator = "➜", -- symbol used between a key and it's label
    group = "+", -- symbol prepended to a group
  },
  window = {
    border = "single", -- none, single, double, shadow
    position = "bottom", -- bottom, top
    margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
    padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
  },
  layout = {
    height = { min = 4, max = 25 }, -- min and max height of the columns
    width = { min = 20, max = 50 }, -- min and max width of the columns
    spacing = 3, -- spacing between columns
    align = "left", -- align columns left, center or right
  },
  ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
  hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
  show_help = true, -- show help message on the command line when the popup is visible
  triggers = "auto", -- automatically setup triggers
  -- triggers = {"<leader>"} -- or specify a list manually
  triggers_blacklist = {
    -- list of mode / prefixes that should never be hooked by WhichKey
    -- this is mostly relevant for key maps that start with a native binding
    -- most people should not need to change this
    i = { "j", "k", "y", "c"},
    o = { "j", "k", "y", "c"},
    v = { "j", "k", "y", "c"},
  },
}
local leader_mappings = {
  ['.'] = { '<cmd>e $MYVIMRC<cr>',             'Open init' },
  ['f'] = { '<cmd>echo "test"<cr>',             'Echo' }
}
require("which-key").register(leader_mappings, {
  mode = "n", -- NORMAL mode
  prefix = "<leader>",
  buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  silent = true, -- use `silent` when creating keymaps
  noremap = true, -- use `noremap` when creating keymaps
  nowait = false -- use `nowait` when creating keymaps
})
EOF

then using the config to open a file like so: nvim --noplugin -u test.vim test.vim

Press "y" or "c". Which-key appears.

Expected behavior

Having "y" or "c" in blacklist would block which-key from being triggered in the given modes.

jemag avatar Jul 06 '21 00:07 jemag

Same here, triggers_blacklist gets ignored. A workaround that works for me is just to enable ignore_missing = true, which will ignore all unlabeled mappings.

pmrt avatar Sep 18 '21 17:09 pmrt

Maybe related, whichkey was creating the following mappings that I didn't want:

n  <aÞ         * <Nop>
n  <a          * <Cmd>lua require("which-key").show("<a", {mode = "n", auto = true})<CR>
n  <iÞ         * <Nop>
n  <i          * <Cmd>lua require("which-key").show("<i", {mode = "n", auto = true})<CR>

This is what worked to force those mappings to not be created:

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

zzzachzzz avatar Nov 15 '22 23:11 zzzachzzz

I'm having a similar issue which breaks a in normal mode:

   aÞ          * <Nop>
        Last set from Lua
   a           * <Cmd>lua require("which-key").show("a", {mode = "", auto = true})<CR>
        Last set from Lua
x  a%            <Plug>(MatchitVisualTextObject)
        Last set from /nix/store/bgjx1gbv6qqdx6lbdc7pr5jmngzky7nb-neovim-unwrapped-0.8.0/share/nvim/runtime/pack/dist/opt/matchit/plugin/matchit.vim line 85

presets.operators["a"] = nil didn't work.

alex35mil avatar Jan 25 '23 13:01 alex35mil

I was able to get back a by not setting mode = "" in the keymaps (I set mode for each keymap individually).

However, these weird keymaps are still generated.

alex35mil avatar Jan 25 '23 13:01 alex35mil

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.

github-actions[bot] avatar Jul 08 '24 01:07 github-actions[bot]