There is more than one door into Insert mode. Each key puts you in a different place, so picking the right one saves extra cursor movement. Press all of these from Normal mode, and press Esc when you have finished typing.
Insert or append at the cursor
iinserts before the character under the cursor.aappends after the character under the cursor.
Suppose the line is ct and the cursor is on c. Press a, type a, then press Esc:
catPressing i at the same spot would have given act.
Start or end of the line
Iinserts before the first non-blank character of the line.Aappends at the end of the line.
A is very useful for adding something to a configuration line, wherever the cursor currently is on it.
PATH=/usr/binPress A, type :/opt/tools/bin, press Esc:
PATH=/usr/bin:/opt/tools/binOpen a new line
oopens a new line below the current one and starts Insert mode.Oopens a new line above it.
You do not need to move to the end of the line first.
Replacing instead of inserting
R enters Replace mode, where typing overwrites existing characters. To change a single character, press r followed by the new one. After r you stay in Normal mode.
Repeating what you typed
A count before an insert command repeats the text. Type 40i- and press Esc to get a line of forty dashes.
The . command repeats your last change. If you used A; and Esc to add a semicolon, move to another line and press . to add one there too.
When things look wrong
If your typing moves the cursor or deletes text, you were still in Normal mode. Press Esc, then u to undo.
In some very small vi setups, arrow keys pressed in Insert mode may type letters such as A or B. Leave Insert mode before moving, or install full Vim.
Pasting from the clipboard
When you paste into Vim through your terminal, enter Insert mode first. Otherwise the pasted characters may be run as commands. If auto-indent makes pasted code drift to the right, :set paste turns that off, and :set nopaste restores it.
Try it
- Run
vim practice.txt. - Press
i, typesecond, pressEsc. - Press
O, typefirst, pressEsc. - Press
j, theno, typethird, pressEsc. - Press
A, typeline, pressEsc. - Press
k, then., and see the same text appended there. - Save and quit with
:wq, then runcat practice.txt.
Check your understanding
Vim Inserting and Appending Text
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.