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

  1. Put the cursor on the w of world.
  2. Press i, type beautiful (trailing space), press Esc. Result: hello beautiful world.
  3. Undo with u.
  4. Put the cursor on the o of hello, press a, type there, press Esc. Result: hello there world.
normalpress i to type · hjkl to move

goal i inserts before the cursor, a inserts after.

I and A — line boundaries

  1. With the cursor anywhere on line 1, press A, type // items list, press Esc.
  2. Move down with j, press I, type let , press Esc.
  3. On the last line press A, add // empty string, press Esc.
normalpress i to type · hjkl to move

goal Use A to append to line ends without navigating there manually.

o and O — open new lines

  1. Put the cursor on the console.log line, press o, type console.log("World");, press Esc.
  2. Put the cursor on the function greet() line, press O, type // Greeting function, press Esc.
normalpress i to type · hjkl to move

goal Insert lines without moving to line ends or using arrow keys.

Choosing the right insert command

  1. Add a ; to the end of every line — use A on each.
  2. Add let to the start of the age line — use I.
  3. Add a comment line // user data above the first — use O on it.
  4. Add const country = "US"; after the city line — use o.
normalpress i to type · hjkl to move

goal Match the insert command to where you need to type.

Real code — fill in the missing pieces

  1. The URL needs the id. Put the cursor on the closing ` after /users/ and use i to insert ${id} before it.
  2. response needs .json(). Press A on that line and type .json().
  3. Add semicolons with A on each line that’s missing one.
normalpress i to type · hjkl to move

goal Use the correct insert command every time.