A lot of people have been mapping jk or kj or kk to ESC in
order to escape insert mode quickly. However, when we press the first key in
these mappings, Vim will wait for timeoutlen
milliseconds before writing this char to buffer. The apparent lag caused by
this behaviour is annoying.
Better-escape.vim is a plugin to help Vim/Nvim users escape from insert mode quickly using their customized key combinations, without experiencing the lag.
- Neovim: 0.4.4 and above
- Vim: 8.0 and above (not tested on Vim 7.4)
Use your favorite plugin manager to install it:
- Use vim-plug:
Plug 'jdhao/better-escape.vim' - Use dein:
call dein#add('jdhao/better-escape.vim') - Use packer.nvim:
use {'jdhao/better-escape.vim', event = 'InsertEnter'} - Use vim-packager:
call packager#add('jdhao/better-escape.vim') - Use minpac:
call minpac#add('jdhao/better-escape.vim')
The default shortcut for leaving insert mode is jk: first press j, then
quickly press k, you will leave insert mode.
By default, the time interval threshold between pressing j and k is set to
150 ms. That is, if the time interval between pressing of k and j is above
the threshold, jk will be inserted literally. Otherwise, we assume you want
to leave insert mode. The time interval can be customized via option g:better_escape_interval:
" set time interval to 200 ms
let g:better_escape_interval = 200If you want to use other shortcut, you can customize via option g:better_escape_shortcut:
" use jj to escape insert mode.
let g:better_escape_shortcut = 'jj'Some people may prefer to use multiple shortcuts. This is also supported:
let g:better_escape_shortcut = ['jk', 'jj', 'kj', 'лл']See :h better-escape.txt.
This plugin is released under the MIT License.