Skip to the workspace
Pebellslearn by building
Editing Files  ›  Lesson

Vim — Modes and Moving Around

Vim 15 minVim starts in Normal mode where keys are commands, i or a or o enter Insert mode for typing, and Esc followed by a colon command saves or quits.

linux / Vim — Modes and Moving Around

Explore each scene at your own pace.

01 · The rule

The rule

Vim — Modes and Moving Around

Sooner or later you'll be logged in to a server with no graphical editor, and a file will need changing. Vim, or its older relative vi, is installed almost everywhere. Newcomers often get stuck in it because they don't know one fact: the keys do different things depending on which mode you're in.

The rule

In Vim, keys are commands until you press i.

Open Asha's notes with:

$ vim ~/garden/notes.txt

Vim starts in Normal mode. Here, letters don't type text. Each one is a command: j moves down a line and x deletes a character. There are three modes to know:

Mode How you get there What keys do
Normal the starting mode; Esc from anywhere move, delete, copy, paste
Insert i, a or o from Normal type text, like any editor
Command-line : from Normal save, quit, search and replace

Three ways into Insert mode:

  • i inserts before the cursor.
  • a appends after the cursor.
  • o opens a new line below and starts typing there.

To get out of a file:

Type (in Normal mode) Result
:w then Enter write (save) the file
:q quit; refuses if you have unsaved changes
:wq save and quit
:q! quit and throw away the changes

Moving in Normal mode:

  • h j k l move left, down, up and right. The arrow keys usually work too.
  • w jumps to the next word and b goes back a word.
  • 0 goes to the start of the line and $ to the end.
  • gg goes to the first line, G to the last, and 5G to line 5.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.