LESSON · 1 OF 6

vim basics

vim basics

vim is installed on almost every Linux system. It is worth knowing the minimum needed to open a file, make a small change, and exit cleanly. Six keystrokes cover that minimum.

Modes, in one paragraph

vim has modes. When you first open a file you're in normal mode, which means keys do things like move the cursor or delete lines, not type letters. To actually type, you switch to insert mode. To save or quit, you switch to command mode. The keys below move you between these modes.

The survival set

bash
vim /root/notes.txt

Once vim opens the file:

  • i - enter insert mode. Now you can type normally.
  • Esc - leave insert mode, back to normal mode.
  • :w - write (save). Type it in normal mode, press Enter.
  • :q - quit. Won't work if you have unsaved changes.
  • :wq - save and quit in one step.
  • :q! - quit without saving. The escape hatch when you opened something by accident.

Two more that pay off often:

  • dd - in normal mode, delete the current line.
  • u - undo the last change.

The famous "how do I exit vim?" moment

If you're stuck in vim and don't know what mode you're in, press Esc a couple of times (you'll be in normal mode for sure), then type :q! and Enter. You'll be out.

That's enough vim to edit configs on any Linux box in the world. Come back to it properly later if you want, but this is the floor.

Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute