I am developing a vim plugin and I have set a default mapping this way.

if !hasmapto('<Plug>DumpDebugString')
    nmap <unique> <Leader>ds  <Plug>DumpDebugString
    nmap <unique> <Leader>dS  <Plug>DumpDebugStringExpr


nnoremap <silent> <Plug>DumpDebugString :<C-U> :call <SID>debugFunctionWrapper(0)<CR>
nnoremap <silent> <Plug>DumpDebugStringExpr :<C-U> :call <SID>debugFunctionWrapper(1)<CR>

When I try invoking ds the DumpDebugString method runs correctly but takes some time actually get called in the first place. It is run instantly only if I map it like this:

nmap <leader>ds <Plug>DumpDebugString<CR>

But the extra <CR> shouldn't be needed since it already included in the nnoremap call.

  • I don't think it has anything to do with the actual mapping characters or with the use of <Plug>.
  • Substituting :call <SID>debugFunctionWrapper(0)<CR> with something like :call str2nr("1")<CR> doesn't seem to solve the problem
  • Adding <nowait> doesn't do anything.

For the story, here's the plugin: https://github.com/bergercookie/vim-debugstring

  • 2
    You can simply your :call's to just :<c-u>call instead of :<c-u> :call May 7 '18 at 20:58

When you press Leader d s, Vim expands the keysequence into <plug>DumpDebugString. However, it doesn't expand the latter immediately, because it waits for you to maybe press Expr afterwards. This is due to the other <plug> mapping:

nmap <nowait> <unique> <Leader>dS  <Plug>DumpDebugStringExpr
                                                        Vim waits `&ttimeout` ms for these keys to be typed

One solution is to surround all your <plug> mappings with parentheses:

nmap <unique> <Leader>ds  <Plug>(DumpDebugString)
nmap <unique> <Leader>dS  <Plug>(DumpDebugStringExpr)

Now, when you press Leader d s, and it gets expanded into <plug>(DumpDebugString), there's no ambiguity anymore. Vim doesn't wait for Expr to be typed because there's no <plug>(DumpDebugString)Expr mapping.

  • 2
    Yeah, that's right! I should have guessed! I resided into changing the DumpDebugString to a different name in the first place as I find it to be more clean but the root cause is the same nonetheless. May 8 '18 at 21:36

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.