Skip to main content
  1. Posts/

Introducing better-esacape.vim: My First Vim/Neovim Plugin

··309 words·2 mins·

After using and learning Neovim for over 2 years, I have finally published my first plugin – better-escape.vim.

Better-escape.vim is a plugin to help users escape from insert mode quickly without experiencing the lagging that comes with Vim mappings.

As a Vim user, a very popular mapping to escape insert mode is to map jj or jk or kj etc. to Esc, since the Esc key is hard to reach without moving your hand from the home row.

inoremap jk <ESC>
inoremap jj <ESC>
inoremap kj <ESC>

However, this comes with an annoyance. If you use jk to escape insert mode, whenever you press j in insert mode, Vim will not write it to the buffer, it will wait for timeoutlen milliseconds to see whether you want to use the jk mapping or you want to input j literally. This issue is easily noticeable when we have a relatively large timeoutlen value.

In my previous post, I have already talked about this topic and provided a solution. The solution is to use an insert mode mapping for k only. When we press k, we check if the previous character is j. If that is true, we will erase previous j and go to normal mode. Otherwise, k is inserted as is. There is no lagging any more. The problem is that now we can not input jk directly in insert mode. To insert k when the previous character is j, we need to press Ctrl-V, then press j.

In better-escape.vim, I have a smarter solution. We will check the time spent between pressing j and k in insert mode. If the time is above a predefined threshold, jk will be inserted literally. Otherwise, we will escape from insert mode. With this plugin, you can easily customize the shortcut for escaping insert mode, as well as the time threshold used.

Related

Migrating from Packer.nvim to Lazy.nvim
··651 words·4 mins
You Do Not Need a Plugin for This Feature
··424 words·2 mins
Migrating from vim-plug to Packer.nvim
··1072 words·6 mins