0

I'm using the Vim REPL plugin, and I'm trying to use a key mapping to call the command REPLToggle. The command is declared here.

My key mapping is:

nnoremap <leader>r :call repl#REPLToggle()<cr>

When I'm using the key, the command is executed only after I press any extra key. For example, I'm pressing <leader>r, nothing is happening, until I press any other key. Though, the extra key is passed to the terminal that is opened.

When I run the command without key mapping, it works as it should be. That is, when I manually do :call repl#REPLToggle(), then all are OK.

The function repl#REPLToggle is defined here.

Can anyone help me with this?

3
  • Does it work if you use nnoremap <leader>r :REPLToggle<cr> instead? It looks like the :REPLToggle command (and not the function) is supposed to be the primary interface to the plugin... Having said that, not sure if they're actually different, but please try it to see if you get a different result.
    – filbranden
    May 22 at 11:32
  • 2
    My guess is you have another mapping that starts with leader-r. Vim has to wait to distinguish them.
    – D. Ben Knoble
    May 22 at 12:46
  • 1
    @D.BenKnoble yes. You are right. Can you please make that a proper answer, so it can be upvoted? :)
    – Xxxo
    May 22 at 14:26
2

When you get a delay after a mapping, it’s generally because vim needs to disambiguate something.

Usually, you have multiple mappings with the same prefix (e.g., <leader>r and <leader>rt)—after the first two keys, vim doesn’t know if you typed the first mapping or started the second. So it waits until another key is pressed (disambiguating) or for a long enough pause to know no more keys are coming (timeoutlen I think? Or updatetime? Something like that.)

You could change the mappings to avoid this.

I also have a plugin popsikey which is designed to help organize mappings under a shared prefix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.