iverse.deviverse.dev

Editing files with Vim

Jem Young4 min

tl;dr

Vim has three modes and you land in the one that ignores your typing. `i`, `ESC`, `:wq` to save and `:q!` to bail — that's enough to edit a file on any server, and the rest is optional forever.

You already have VS Code, and it is better at almost everything. The reason to learn Vim isn't that it beats your editor — it's that it is already installed on the server you just rented, and VS Code is not.

Three modes, and you start in the wrong one

This is the whole reason Vim feels broken the first time. You open a file, type, and nothing appears — because you are in normal mode, where letters are commands, not text.

Three boxes — insert, normal and command — with i and Escape between normal and insert, and colon and Escape between normal and command.
Normal is the hub. Every mode change goes through it, and ESC always gets you back.

ESC returns to normal from anywhere. That single key is most of what saves you.

The exercise

cd ~
mkdir temp
cd temp
vi test         # vim test works too — same editor

Then i, write a few lines, ESC, and :wq to write and quit. vi test creates the file if it doesn't exist, so touch first is optional.

The four keys that get you out

ESCback to normal mode, from anywhere
uundo the last change (in normal mode)
:wqwrite and quit
:q!quit and throw the changes away
:syntax oncolour the code you're editing

That last one is the escape hatch. Plain :q refuses when you have unsaved changes; the ! means do it anyway. You will need it the first time you open a file by accident.

Why bother past that

Jem's argument isn't speed for its own sake — it's that once you stop reaching for the mouse, both hands stay on the keyboard. The people he's seen use Vim at work are genuinely fast, but he's blunt about the cost: it takes a long time and real dedication, because it isn't a natural way to work for most people.

So this lesson stays at the surface deliberately — about ten minutes, enough to open a file on a server, change a line, and get out. If you want the rabbit hole, the course points at ThePrimeagen's four-hour Vim Fundamentals and openvim.com.

← all Full Stack Fundamentals, v3 posts