Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mappings with <expr> evaluated too early #197

Open
mikehaertl opened this issue Jun 10, 2021 · 1 comment
Open

Mappings with <expr> evaluated too early #197

mikehaertl opened this issue Jun 10, 2021 · 1 comment

Comments

@mikehaertl
Copy link

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.

@TsukiGva2
Copy link

same problem here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants