As you might guess, insert mode is used to insert text into the buffer.
The most common way to switch from normal mode to insert mode is to type i, but this is such a common operation that Vim provides a variety of commands that fine-tune how it does so. Additionally, each of these commands accepts an optional count:
Command | Action |
---|---|
i | insert text before the cursor N times |
a | append text after the cursor N times |
s | (substitute) delete N characters [into register x] and start insert |
I | insert text before the first CHAR on the line N times |
A | append text after the end of the line N times |
S | delete N lines [into register x] and start insert; synonym for "cc". |
C | change from the cursor position to the end of the line, and N-1 more lines [into register x]; synonym for "c$" |
Let's take a look at a few of these to get a better idea of some of the functionalities that are available. First, let's look at entering insert mode using i:
Note that in Step 1 the editor is in normal mode, and the cursor covers the entire character at its current position, while in Step 2 the editor is in insert mode, with a "bar" style cursor that is located before the cursor.
Compare that behavior with that of using a, as shown in the following example. Repeating that example produces the following:
The main difference is in Step 2, where entering insert mode with a places the cursor after the current position.
Finally, let's compare both of the previous examples with the behavior of entering insert mode with s:
In this case, the character under the cursor is deleted, then new text is inserted in its place.
As shown in the table above, each of these commands has a "capitalized" version that has a similar behavior, but performed on the line-level. It can be a big benefit to practice each of these and commit them to muscle memory.