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/Nvim will wait for timeoutlen
milliseconds before writing this char to buffer. The apparent lag caused by
this behaviour is annoying.
Better-escape.vim is created to help Vim/Nvim users escape 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:
- packer.nvim:
use {'jdhao/better-escape.vim', event = 'InsertEnter'}
- vim-plug:
Plug 'jdhao/better-escape.vim'
- dein:
call dein#add('jdhao/better-escape.vim')
- vim-packager:
call packager#add('jdhao/better-escape.vim')
- minpac:
call minpac#add('jdhao/better-escape.vim')
This plugin works out of the box. The default shortcut for escaping insert mode
is jk
, that is, pressing j
first, then pressing k
quickly, you will
leave insert mode.
If you want to use other shortcuts, you can customize via option g:better_escape_shortcut
:
" use jj to escape insert mode.
let g:better_escape_shortcut = 'jj'
By default, the time interval threshold between pressing j
and k
is 150 ms.
That is, if the time interval between pressing k
and j
is above the
threshold, jk
will be inserted literally. Otherwise, we assume you want to
leave insert mode. The threshold can be customized via option g:better_escape_interval
:
" set time interval to 200 ms
let g:better_escape_interval = 200
Some people may prefer to use multiple shortcuts. This is also supported:
# non-ASCII shortcuts are also supported for non-English keyboard.
let g:better_escape_shortcut = ['jk', 'jj', 'kj', 'лл']
Sometimes, you may wonder why the given escape shortcut does not work as intended.
Maybe it is because you have not pressed the two keys fast enough.
To get the interval between key presses and help you to set a reasonable interval,
use the option g:better_escape_debug
:
" enable debug (some message will be shown)
let g:better_escape_debug = 1
Then run command :messages
to check the debug log.
See :h better-escape.txt
.
This plugin is released under the MIT License.
- https://github.com/Krafi2/jeskape.nvim
- https://github.com/zhou13/vim-easyescape
- https://github.com/max397574/better-escape.nvim (a lua re-implementation of this plugin)