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

Getting weird error when launching Fern #250

Closed yatesco closed 11 months ago

yatesco commented 11 months ago

Environment (please complete the following information):

nnoremap :WhichKey '' nnoremap :WhichKey ',' set timeoutlen=500

" additional iterators for tabs nmap T] :tabnew nmap [t :tabprevious nmap ]t :tabnext nnoremap <C-^> " DO NOT map jk to ESC, use C-[ instead ;-) let g:which_key_map = { \ ' ' : [':', ':'], \ 'P' : ['Fern . -drawer -reveal=% -toggle -width=35', 'Fern'], \ } call which_key#register('', "g:which_key_map")


**Describe the bug**
Using the above, executing `<space>P` shows the following error: `[which-key] <Space> - is undefined` AND the character under the cursor is replaced with `n`(!).

If I remove `<CR>` from the `which_key_map`:
```vim
let g:which_key_map = {
      \ ' ' : [':', ':'],
      \ 'P' : ['Fern . -drawer -reveal=% -toggle -width=35', 'Fern'],
      \ }

then nothing happens.

I can confirm that Fern . -drawer -reveal=% -toggle -width=35 in the command area opens Fern as I would expect.

To Reproduce Steps to reproduce the behavior:

  1. Create the minimal vimrc min.vim:
set nocompatible
set runtimepath^=/path/to/vim-which-key
syntax on
filetype plugin indent on

let g:mapleader = "\<Space>"
let g:maplocaleader = ','

nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>
set timeoutlen=500

" additional iterators for tabs
nmap T] :tabnew<CR>
nmap [t :tabprevious<CR>
nmap ]t :tabnext<CR>
nnoremap <BS> <C-^>
" DO NOT map jk to ESC, use C-[ instead ;-)
let g:which_key_map = {
      \ ' ' : [':', ':'],
      \ 'P' : ['Fern . -drawer -reveal=% -toggle -width=35<CR>', 'Fern'],
      \ }
call which_key#register('<Space>', "g:which_key_map")
  1. Start (neo)vim with command: vim -u min.vim

  2. Type <space>P

  3. See error

Expected behavior Fern should open correctly without the <CR>.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

liuchengxu commented 11 months ago

It should work by adding : before Fern . -drawer -reveal=% -toggle -width=35<CR>. Tested locally, let me know if this does not work for you.

let g:which_key_map = {
      \ ' ' : [':', ':'],
      \ 'P' : [':Fern . -drawer -reveal=% -toggle -width=35<CR>', 'Fern'],
      \ 
yatesco commented 11 months ago

works fine - thank you! I'm not clear on when the ':' is needed or not...