11

I'm trying to make Vim wait after the leader key indefinitely without messing with the timeoutlen of other keys. Currently I have this lines in my vimrc:

let mapleader=" "
set timeoutlen=2000 ttimeoutlen=0

Setting ttimeoutlen make commands such as ciw last permanently.

The Spacemacs plugin for Emacs which has a nice set of default configurations, one of these is that the leader key waits indefinitely. Can I do this on Vim by any other way than changing the timeoutlen values?

muru
  • 24,838
  • 8
  • 82
  • 143
tjbrn
  • 563
  • 3
  • 12
  • What do you mean by makeing the key persistent? Isn't it persistent, once you put this in your .vimrc? – Christian Brabandt Jan 08 '16 at 18:55
  • Sorry, I mean last longer. For example, in my case if I start type in normal mode "..." , the command only last for 2 seconds. What I want is Vim wait for the entire command or until I press ESC. – tjbrn Jan 08 '16 at 19:03
  • You mean the timeout? Does :h 'timout' help you? – Christian Brabandt Jan 08 '16 at 19:05
  • 1
    Not much, since I can't found anything about key specific timeout. (I want just the leader key to wait the command) – tjbrn Jan 08 '16 at 19:11

2 Answers2

4

Here is a dirty workaround you could consider:

" Increase timeoutlen when <Leader> is pressed
" Only one of these lines is needed.  I am not sure which is most recommended.
"nmap <silent> <Leader> :<C-U>set timeoutlen=99999 ttimeoutlen=99999<CR><Leader>
nnoremap <silent> <Leader> :<C-U>set timeoutlen=99999 ttimeoutlen=99999<CR>:call feedkeys('<Leader>')<CR>

" Reset timeoutline to normal soon afterwards
autocmd CursorMoved * set timeoutlen=2000 ttimeoutlen=0

The CursorMoved event is not ideal but it usually gets triggered sooner or later. You may be able to find other events or mappings to reset the values in those cases when you get stuck on the long timeout.

joeytwiddle
  • 3,622
  • 19
  • 28
3

If you do :set notimeout nottimeout mappings won't time out. This is all explained very well at :h 'timeout' You might try other combinations of those two mappings.

Christian Brabandt
  • 25,820
  • 1
  • 52
  • 77