Key-specific timeoutlen in vim
The solution proposed by Ingo Karkat will affect all insert mode mappings, so it may break plugins that define other insert mode mappings that are hard to type in so short a time period.
In order to escape from insert mode without lagging, I have found a smarter way, which leads to plugin better-escape.vim.
The default shortcut to escape insert mode is jk
, you can change it via the following option:
let g:better_escape_shortcut = 'jj'
It will calculate the time interval between pressing the first char and the second char in the shortcut (the default is 150 ms). If you press those two chars quickly, you will leave insert mode. Otherwise, the characters will be written literally. To adjust the time interval, use the following option:
let g:better_escape_interval = 200
There's nothing built-in. With regards to your mapping, you probably mean :inoremap jj <Esc>
, and for that to apply quickly, you just need to ensure that there are no other insert mode mappings that start with jj
. To avoid that the first j
appears only with a delay, you could use :autocmds
to toggle the 'timeoutlen'
value:
:autocmd InsertEnter * set timeoutlen=200
:autocmd InsertLeave * set timeoutlen=1000