Mappings with <expr> evaluated too early
Opened this issue · 1 comments
Environment:
- OS: Linux Mint
- (Neo)Vim version: NVIM v0.5.0-dev+1354-ga282a177d
- vim-which-key version: da2934f
- Have you reproduced with a minimal vimrc: yes
Describe the bug
I want to use a <expr>
mapping like this:
`" r: ripgrep
nnoremap <expr> <leader>rg ":Rg " . input('rg search pattern: ') . "\<ESC>"
When I hit <leader>rg
it will ask me for a search pattern and then execute :Rg mypattern
.
If I only press <leader>
and wait it should bring up the which-key menu as usual. But instead it prompts me fo the search pattern now:
<leader>
rg search pattern:
To Reproduce
Here the relevant parts from my config
let g:which_key_map = {}
let g:which_key_map.r = {
\ 'name' : '+ripgrep',
\ 'g' : 'grep'
\}
call which_key#register(',', "g:which_key_map")
let mapleader = "," " Map <leader> to , instead of default \
nnoremap <silent> <leader> :WhichKey ','<CR>
" r: ripgrep
nnoremap <expr> <leader>rg ":Rg " . input('rg pattern: ') . "\<ESC>"
Expected behavior
When hitting <leader>
it should show the which-key menu.
Additional context
This is related to #60 and the fix in 80a1e88.
It seems like the plugin now evaluates all {rhs}
of type <expr>
when :WhichKey
is invoked. But that's a problem if the expression must not be executed before the actual keys are used.
Actually the whole point of using expressions is probably to do some calculation on runtime. So I think the fix should be reverted / improved.
same problem here