4

I'm using <c-w><space> to open current terminal buffer in a new tab:

tnoremap <c-w><space> <c-w>:tab split<cr>

This map cause <c-w><c-w> trigger mapping delay in terminal mode, why would that happen? Are there any relation between <space> (0x20) and <c-w> (0x17) ?

The <c-w><space> works fine, it doesn't trigger mapping delay.

I have created an rc file with this single command and tested it with vim -Nu rc, the result didn't change.

FWIW, I also use this map in normal mode:

nnoremap <c-w><space> :tab split<cr>

It works fine, it doesn't affect <c-w><c-w> int normal mode.

I'm using vim8.1-2300, ubuntu 18.04.4, zsh 5.4.2

2
  • 3
    For some reason, C-w is not written in the typeahead immediately (not printed in the 'showcmd' area). Maybe Vim waits for &timeoutlen ms to determine whether the key must be remapped or executed with its default meaning (start a C-W command, as set by 'termwinkey'). I guess that the key assigned to 'termwinkey' is handled differently in Terminal-Job mode compared to C-w in normal mode. You could somewhat get around the timeout by installing this mapping: tno <c-w><c-w> <c-w><c-w>.
    – user938271
    Apr 29, 2020 at 14:23
  • 1
    @user938271 Nice observation, I tested it with 2000 timeoutlen, it woks like you described, the workaround works too! I think you can post that as an answer.
    – dedowsdi
    Apr 29, 2020 at 14:39

1 Answer 1

4

For some reason, C-w is not written in the typeahead immediately (not printed in the 'showcmd' area).

It seems that Vim waits for &timeoutlen ms to determine whether the key must be remapped or executed with its default meaning (start a C-W command). I guess that the key assigned to 'termwinkey' is handled differently in Terminal-Job mode compared to C-w in normal mode.

You could somewhat get around the timeout by installing this mapping:

tno <c-w><c-w> <c-w><c-w>

This works under the assumption that you didn't reset 'termwinkey', and as a result Vim uses <C-w> to start a C-W command. This wouldn't work if you've reset the option to, let's say, <C-s>, and you press <C-s><C-w> to focus another window.

For something more reliable, you could try this:

augroup termwinkey_no_timeout
    au!
    au TerminalWinOpen * let b:_twk = &l:twk == '' ? '<c-w>' : &l:twk
      \ | exe printf('tno <buffer><nowait> %s<c-w> %s<c-w>', b:_twk , b:_twk)
      \ | unlet! b:_twk
augroup END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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