Subscribe:   RSS icon   twitter icon

A Little Vim Trick

Lee Phillips
August 15th, 2021

This may be obvious to Vim veterans, but I’ve been using Vim for years and only found out about this trick recently. It makes it faster and easier to switch from insert mode to normal mode. Effective use of Vim means switching between modes constantly, so this little trick makes a big cumulative difference in your Vim efficiency. For me, it makes using Vim more pleasant as well, as it eliminates a small but constant annoyance.

To switch from insert mode (the mode where you are typing in text) to normal mode (the mode in which Vim starts up, where you enter commands for movement, etc.) you type the Escape key. As that’s a big stretch with the left pinky on most keyboards, some people use the control combination for Escape, which is Control-[. This may not sound like much of an improvement, but it is because such people also generally map their CapsLock key to Control. Doing these two things means you can enter Escape with small movements, staying close to the home row.

There are two problems with this. First, it still requires too much movement for something that we’re constantly doing. Both hands need to leave the home row, and the [ key is a pinky movement (these obsessions are mostly of interest to those who touch type). Second, there is a delay before Vim actually switches to normal mode. The delay is the same if we hit the dedicated Escape key.

The reason for the delay is that there are other commands that begin with Escape, and Vim is waiting through its timeout to decide that the Escape you just entered is not the first part of one of those commands. This delay is annoying, especially if you make it obvious by setting up your Vim so that the cursor and/or status bar changes color to remind you of the current mode.

One small setting in your .vimrc file solves both of these problems:

inoremap <C-j> <Esc>

Naturally, you may need to use another mapping if you’re already using this one.

First, it’s faster and easier to type, because the j key is under your right index finger (no offense intended to Dvorak users—you probably want to use something else). Second, this totally eliminates the delay.

It’s amazing how such a tiny thing can make Vim so much more pleasant to use. I hope you find it useful.

Share with Facebook Share with Twitter Share with Reddit Share with Slashdot
▶ Comment is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to
Quotilizer ... loading ...

Tenuously related:

The best tool for CVs with publication lists.