liuchengxu/vim-which-key

Show only the mappings provided by dictionary

ArianaAsl opened this issue · 7 comments

Is your feature request related to a problem? Please describe.
I would like whichkey to display only the mappings i provide in its dictionary instead of all the mapping provided by plugins etc...

Describe the solution you'd like
Disable the displaying of any mapping that is abscent in the dictionary

Describe alternatives you've considered
Tried using the ignore option but that'll take too much time and not all options are ignored. for instance the mapping c$ cannot be ignored since that is seen as an error by vim

Additional context
My current Whichkey settings
let g:which_key_map = {
\ 'n' : ['NERDTree' , 'NERDTree Toggle'] ,
\ 'v' : ['Vifm' , 'Vifm'] ,
\ 'r' : ['Ranger' , 'Ranger'] ,
\ 't' : ['Terminal' , 'Terminal'] ,
\ 'T' : ['NewTab' , 'NewTab'] ,
\ 'd' : ['Duplicate Cleaner' , 'Delete Duplicate Lines'] ,
\ 'm' : ['MRU' , 'View File History'] ,
\ 'cc' : ['Comment Out' , 'Comment Out'] ,
\ 'cu' : ['Uncomment' , 'Uncomment'] ,
\ '1-9' : ['Go To Tab By Number' , 'Go To Tab By Number 0 Is Tab 10'] ,
\ 'F8' : ['Open MD Server' , 'MD Server'] ,
\ 'F2' : ['Web Server' , 'Web Server'] ,
\ 'F3' : ['Web Server' , 'Web Server Reload'] ,
\ 'F4' : ['Web Server' , 'Web Server Stop'] ,
\ 'F6' : ['Spellcheck' , 'Spellcheck'] ,
\ 'C-vimkeys/arrows' : ['Move Between Splits' , 'Move Between Splits'] ,
\ 'S-arrows' : ['Resize Splits' , 'Resize Splits'] ,
\ 'Alt-arrows' : ['Tab Right Or Left' , 'Tab Right OR Left'] ,
\ 'c' : ['Colors' , 'Colors'] ,
\ 'b' : ['Buffers' , 'Buffers'] ,
\ 's' : ['Files' , 'Files'] ,
\ 'W' : ['Windows' , 'Windows'] ,
\ 'H' : ['History' , 'History'] ,
\ 'Hc' : ['CMD History' , 'CMD History'] ,
\ 'M' : ['Maps' , 'Maps'] ,
\ 'w' : ['Quick Save' , 'Quick Save'] ,
\ 'tm' : ['TabMove' , 'TaBMove'] ,
\ 'z' : ['SpellCorrect' , 'SpellCorrect'] ,
\ 'op' : ['Source vimrc' , 'Source vimrc'] ,
\ }

let g:which_key_map.1 = 'which_key_ignore'
let g:which_key_map.2 = 'which_key_ignore'
let g:which_key_map.3 = 'which_key_ignore'
let g:which_key_map.4 = 'which_key_ignore'
let g:which_key_map.5 = 'which_key_ignore'
let g:which_key_map.6 = 'which_key_ignore'
let g:which_key_map.7 = 'which_key_ignore'
let g:which_key_map.8 = 'which_key_ignore'
let g:which_key_map.9 = 'which_key_ignore'
let g:which_key_map.0 = 'which_key_ignore'
let g:which_key_map.cA = 'which_key_ignore'
let g:which_key_map.ca = 'which_key_ignore'
let g:which_key_map.cb = 'which_key_ignore'
let g:which_key_map.ci = 'which_key_ignore'
let g:which_key_map.cm = 'which_key_ignore'
let g:which_key_map.cl = 'which_key_ignore'
let g:which_key_map.cn = 'which_key_ignore'
let g:which_key_map.cs = 'which_key_ignore'
let g:which_key_map.cy = 'which_key_ignore'
let g:which_key_map.c = 'which_key_ignore'

let g:which_key_hspace = 5
let g:which_key_centered = 1
let g:which_key_flatten = 1
let g:which_key_max_size = 1
let g:which_key_disable_default_offset = 1

Makes sense.

I'm not sure what combination to handle:

  1. e.g. g:which_key_ignore_outside_mappings.
  2. :WhichKey! g:dict v:true "to ignore mappings outside g:dict
  3. call which_key#register('<Space>', 'g:dict', 'n', ignore_outside_mappings) "Optional 4th argument interpreted as bool

I have the 3rd option working in a test branch. 2nd option will be messy to handle in vimscript, would need to change <args> to <q-args> and parse quotes. 1st is trivial to do, and handle the optional 2nd and 3rd options as overrides to that? I think that makes the most sense.

Is the 1st option, just setting a global, sufficient for your use-case?

The 2nd option worked perfectly for me I just had to rename my dictionary to g:dict and all is fine now. Thanks for the help.

I believe the behaviour of :WhichKey! {dict} was changed with #214 and now shows mappings outside the elements of the dictionary. It appears you're using an older revision which works for you. The name of the dictionary g:dict doesn't matter, you can name it whatever you want, e.g. g:leet_keymap.

I'll go ahead and do the 1st option, the global, with the default being showing mappings outside the dictionary.

I believe I'm using the latest version since I installed the plugin with [Plug 'liuchengxu/vim-which-key'].

:PlugUpdate updates your plugins when using junegunn/vim-plug.

you mean installing the plugin using vim plug doesnt install the latest version? Since I installed whichkey 2 nights ago!

Installing with vim-plug should install the latest version at the time it was commanded to.
Your observations regarding :WhichKey! remain contrary to what I'd expect. It was a few days ago that the behaviour of :WhichKey! was changed to support another bug report.