liuchengxu / vim-which-key

:tulip: Vim plugin that shows keybindings in popup
https://liuchengxu.github.io/vim-which-key/
MIT License
1.93k stars 65 forks source link

Name <Tab> prefix #212

Closed ArtemSmaznov closed 2 years ago

ArtemSmaznov commented 2 years ago

Environment (please complete the following information):

Describe the bug I have several bindings set to <leader><Tab> and they show correctly in Which-Key but the group is named as "+prefix" as per default. I have spend a while trying to figure out how to change the name for the Tab group and have finally found that it shoud be referenced as <Tab> and not as <TAB>. The group gets anmed correctly but it stops showing the actual bindings if I do this.

Not naming the group works as expected: image

Naming the group works but keybinginds are not shown anymore: image

Trying to name them manually only adds w as the name for some reason (tested and w is the second ccharacter of the name for each binding and will change accordingly for each one): image

The same syntax works without problem for other prefixes like <leader>b and even <leader><space> so I am completely lost why <Tab> behaves like this and if this can be resolved somehow with my config.

To Reproduce Steps to reproduce the behavior:

  1. Create the minimal vimrc min.vim:
syntax on
filetype plugin indent on

let g:mapleader = " "

" register dictionary for the <Space>-prefix
call which_key#register(' ', "g:which_key_map")
nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>

" Define prefix dictionary
let g:which_key_map =  {}

if has_key(plugs, 'vim-which-key') | let g:which_key_map['<Tab>']      = { 'name' : '+workspace' }   | endif
" if has_key(plugs, 'vim-which-key') | let g:which_key_map['<Tab>']['0'] = 'Switch to final workspace' | endif
" if has_key(plugs, 'vim-which-key') | let g:which_key_map['<Tab>']['1'] = 'Switch to 1st workspace'   | endif

map <leader><Tab>0 :$tabnext<cr>
map <leader><Tab>1 :1tabnext<cr>
  1. Press Space + Tab

Expected behavior There should be bindings for Space+Tab+0 nad Space+Tab+1

Screenshots There are no bindings. If you uncomment the 2 lines with names it the bindings should say the appropriate string but they only display the second characted of the string (w in this instance for both) If you comment all 3 lines then the bindings are shown correctly but the <Tab> group is not named

Additional context I have tried different variations of referring to Tab like <TAB>, <Tab>, <tab>, tab, TAB, \<Tab> and even an actual tab symbol with no success.

rene-descartes2021 commented 2 years ago

referenced as and not as .

In your bug report you can use &lt; and &gt; to use angle brackets <>, or enclose them with single backticks.

I took a glance and it looks like in which_key#mappings#parse() <Tab> instances in keymappings are replaced with the equivalent <C-I> (see :help keycodes), so that they're all merged together. The implementation looks a bit buggy right now as you noticed.

In your mappings and descriptions you can use <C-I> instead of <Tab> for now. In my simple testing they (native keymappings and vim-which-key descriptions) are merged and displayed in the vim-which-key popup labeled "TAB" well enough, though duplicated in my interactive test.

ArtemSmaznov commented 2 years ago

Apologies - I did not notice that the <> parts were not rendered. I have updated the text now. Is this what you meant? Compared to having no which-key descriptions whatsoever the only difference I see is that now I have 2 tab entries in the root of which key both titled correctly but the individual bindings inside the tab prefix are still not named so not sure this is any better. Or did I misunderstand what you meant? image