level 03
Inserting Text
Enter Insert mode the right way: i, a, I, A, o, O.
You can move. Time to write. There’s no single “insert” key in Vim, there are six, and each one drops you into Insert mode at a different spot. That sounds like overkill until you realize the right one saves you the trip: A types at the end of the line from anywhere, o opens a fresh line without a single arrow press. Pick well and you barely move before you type.
Entering Insert Mode
i → insert before the cursor
a → insert after the cursor (append)
I → insert at the first non-blank of the line
A → insert at the end of the line
o → open a new line below and insert
O → open a new line above and insert
A and o are especially handy: A appends to a line end without navigating there, o starts a fresh line from anywhere.
Leaving Insert Mode
Press Esc (or Ctrl+[) to return to Normal mode. The habit to build: Insert mode is for typing only. As soon as you’re done, drop back to Normal mode — don’t navigate or delete chunks while in Insert.
i vs a — before or after
- Put the cursor on the
wofworld. - Press
i, typebeautiful(trailing space), pressEsc. Result:hello beautiful world. - Undo with
u. - Put the cursor on the
oofhello, pressa, typethere, pressEsc. Result:hello there world.
goal i inserts before the cursor, a inserts after.
I and A — line boundaries
- With the cursor anywhere on line 1, press
A, type// items list, pressEsc. - Move down with
j, pressI, typelet, pressEsc. - On the last line press
A, add// empty string, pressEsc.
goal Use A to append to line ends without navigating there manually.
o and O — open new lines
- Put the cursor on the
console.logline, presso, typeconsole.log("World");, pressEsc. - Put the cursor on the
function greet()line, pressO, type// Greeting function, pressEsc.
goal Insert lines without moving to line ends or using arrow keys.
Choosing the right insert command
- Add a
;to the end of every line — useAon each. - Add
letto the start of theageline — useI. - Add a comment line
// user dataabove the first — useOon it. - Add
const country = "US";after thecityline — useo.
goal Match the insert command to where you need to type.
Real code — fill in the missing pieces
- The URL needs the id. Put the cursor on the closing
`after/users/and useito insert${id}before it. responseneeds.json(). PressAon that line and type.json().- Add semicolons with
Aon each line that’s missing one.
goal Use the correct insert command every time.