Learn Practice Daily golf Reference

How to type text in Vim (Insert mode)

Press i and the bottom line shows -- INSERT --. Now the keys type into the file. Press Esc to stop typing and go back to Normal mode. a, A, I, o and O start typing in other places.

The ninja stepping through a small open door set into a row of letter tiles, a glowing green typing bar just inside the doorway, an i keycap on a sign above the door.

You opened the shop's specials note in Vim to fix the burrito line, and typing doesn't work. The letters you type don't appear. The cursor jumps about instead, and a line may even have gone missing. Vim opens in Normal mode, where every key is a command. In Normal mode x deletes a character and j moves down a line.

i is the way in. While -- INSERT -- shows at the bottom, keys type text and Enter starts a new line, as in any other editor. Esc takes you back out to Normal mode.

Before
Al burrito 9.50
ipastor Esc
Al pastor burrito 9.50
Everything typed after i lands in front of the letter the cursor was on, until Esc stops it
Try it here

Fix the burrito

The burrito on the specials note is missing its filling. The cursor is on the b of burrito.

Press i, type pastor with the space after it, then press Escspecials.txt
1Friday specials
2Al burrito 9.50
1Churros
NORMALLoading the editor…0.0sLn 2, Col :4
Open this text in the playground

This editor needs a keyboard. Read on, and play it at your computer.

Start typing in the right place

Moving the cursor first and then pressing i always works. Vim also has a key for each place you'll want to start, and it moves there and switches to Insert mode in one press.

a starts typing after the letter under the cursor instead of in front of it. You'll use it more than you'd guess, because Esc leaves the cursor on the last letter you typed. To carry on where you stopped, press a.

A starts at the end of the line, wherever the cursor is on it. I starts at the beginning, after the indent. o opens a new empty line below the cursor's line and puts you on it, and O opens one above.

Try it here

Finish the specials

The churros need a price, and there's a drink to add. The cursor is at the start of the churros line.

Add the price at the end with A. Type 3.00, space first, then press Escspecials.txt
2Friday specials
1Al pastor burrito 9.50
3Churros
NORMALLoading the editor…0.0sLn 3, Col :1
Open this text in the playground

This editor needs a keyboard. Read on, and play it at your computer.

Check yourself

Typing at the start of an indented line

The line is indented by two spaces and the cursor is on the last 0 of the price. In Normal mode you press I, type NEW with its space, then press Esc. What does the line say now?

BeforeJust a picture: pick an answer below (1, 2, 3)
1 Horchata 2.50
NORMAL
Pick an answer (click it, or press its number), then watch the engine play the keys to check it.

Fix a slip without leaving Insert mode

A few keys do something special while you're typing. Ctrl-w (hold Ctrl and press W) deletes the word just before the cursor, which is quicker than holding Backspace when a word came out wrong. Ctrl-u deletes everything you've typed on the line since you started typing. Press it a second time and it clears the rest of the line before the cursor too.

Ctrl-o lends you Normal mode for one command and then puts you straight back into Insert mode. In Normal mode 0 jumps to the start of the line, so pressing Ctrl-o then 0 carries your typing over to the front of the line you're on.

Practise the keys

Keys for while you type

Each one starts in Insert mode. Press the keys you'd use.

Which key does it?
You've just typed a word with a typo in it. Delete the word and keep typing.
scroll here, then press it
1 of 4
You've just typed a word with a typo in it. Delete the word and keep typing.
KeysWhat they do
iStart typing in front of the character under the cursor.
aStart typing after the character under the cursor.
IStart typing at the beginning of the line, after the indent.
gIStart typing in column one, before the indent.
AStart typing at the end of the line.
oOpen a new line below and start typing on it.
OOpen a new line above and start typing on it.
A count, like 3iRepeats what you type. 3i, then ab and Esc, types ababab.
EscStop typing and go back to Normal mode.
Ctrl-wIn Insert mode, delete the word before the cursor.
Ctrl-uIn Insert mode, delete what you typed on this line. Again, and it deletes the rest before the cursor.
Ctrl-oIn Insert mode, run one Normal-mode command, then keep typing.