More Ways to Insert Text

You have inserted text before the cursor with the sequence:

itext to be inserted ESC

You’ve also inserted text after the cursor with the a command. Here are some other insert commands for inserting text at different positions relative to the cursor:

A

Append text to end of current line.

I

Insert text at beginning of line.

o (lowercase letter “o”)

Open blank line below cursor for text.

O (uppercase letter “o”)

Open blank line above cursor for text.

s

Delete character at cursor and substitute text.

S

Delete line and substitute text.

R

Overstrike existing characters with new characters.

All of these commands place you in insert mode. After inserting text, remember to press ESC to return to command mode.

A (append) and I (insert) save you from having to move your cursor to the end or beginning of the line before invoking insert mode. (The A command saves one keystroke over $a. Although one keystroke might not seem like much of a saving, the more adept—and impatient—an editor you become, the more keystrokes you will want to omit.)

o and O (open) save you from having to insert a carriage return. You can type these commands from anywhere within the line.

s and S (substitute) allow you to delete a character or a whole line and replace the deletion with any amount of new text. s is the equivalent of the two-stroke command cSPACE, and S is the same as cc. One of the best uses for s is to change one character to several characters.

R (“large” replace) is useful when you want to start ...

Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.