Vim Insert Mode

The Composer's State

Vim Logo
Vim Logo
© Mohammed Saed

Introduction


Most of Vim’s commands are triggered from other modes, but some functionality is within easy reach from Insert mode. In this post, we’ll explore these commands. Although delete, yank and put commands are all triggered from Normal mode, we’ll see that there is a convenient shortcut for pasting text from registers without leaving Insert mode.

We’ll also see that Replace mode is a special case of Insert mode, which overwrites existing characters in the document. We’ll learn how to invoke this and consider some scenarios where it proves useful. We’ll also meet Insert Normal mode, a submode that lets us fire a single Normal mode command before dropping us back into Insert mode.

Make Corrections Instantly from Insert Mode


If we make a mistake while composing text in Insert mode, we can fix it immediately. There’s no need to change modes. Besides the backspace key, we can use a couple of other Insert mode commands to make quick corrections.

Touch typing is more than just not looking at the keyboard; it means doing it by feel. When touch typists make an error, they know it even before their eyes process the information on the screen in front of them. They feel it in their fingers, like a misplaced step.

When you make a typing error, you can use the backspace key to erase the mistake and then make a correction. As long as the error appears near the end of the word, this may be the quickest strategy for making amends. But what if the mistake was at the start of the word? Even worse what if it was at the start of the line?

You could - of course - switch to Normal mode, navigate to the start of the word, fix the error, then hat A to return to where you left off in Insert mode. That little dance could take longer than a second, and it would do nothing to improve your touch-typing skills. Just because you can switch modes doesn’t mean that you should.

In Insert mode, the backspace key works just as you would expect: it deletes the character in front of the cursor. The following chords are also available to use:

KeystrokesEffect
<C-h>Delete back one character (backspace)
<C-w>Delete back one word
<C-u>Delete back to start of line

These commands are not unique to Insert mode or even Vim. We can also use them in Vim’s command line as well as in the bash shell.

Get Back to Normal Mode


Insert mode is specialized for one task –entering text– whereas Normal mode is where we spend most of our time (as the name suggests). So it’s important to be able to switch quickly between them. This tip demonstrates a couple of tricks that reduce the friction of mode switching.

The classic way of getting back to Normal mode is with the <Esc> key, but on many keyboards that can seem like a long reach. Alternatively, we can press <C-[>, which has exactly the same effect.

KeystrokesEffect
<Esc>Switch to Normal mode
<C-[>Switch to Normal mode
<C-o>Switch to Insert Normal mode

Vim novices frequently become fatigued by the constant need to switch modes, but with practice it start to feel more natural. Vim’s modal nature can feel awkward in one particular scenario: when we’re in Insert mode and we want to run only one Normal command and then continue where we left off in Insert mode. Vim has a neat solution to ease the friction caused by switching modes: Insert Normal mode.

Meet Insert Normal Mode


Insert Normal mode is a special version of Normal mode, which gives us one bullet. We can fire off a single command, after which we’ll be returned to Insert mode immediately. From Insert mode, we can switch to Insert Normal mode by pressing <C-o>.

When the current line is right at the top or bottom of the windows, I sometimes want to scroll the screen to see a bit more context. The zz command redraws the screen with the current line in the middle of the window, which allows me to read half a screen above and below the line I’m working on. I’ll often trigger this from Insert mode by tapping out <C-o>zz. That puts me straight back into Insert mode so that I can continue typing uninterrupted.

Paste from a Register Without Leaving Insert Mode


Vim’s yank and put operations are usually executed from Normal mode, but sometimes we might want to paste text into the document without leaving Insert mode.