learn / vim / v2 · 1 of 1 · 7 min
Home row, words, lines and whole files — get anywhere in a few keystrokes, then start typing exactly where you mean to.
## Your hands never leave home
In Normal mode, the four keys under your right hand are the arrow keys:
k
▲
h ◀ ▶ l
▼
jhleft,lright (they're on the left and right ends)jdown (it has a hook that points down)kup
The arrow keys work too. But hjkl keeps your fingers on the home row, which is where the speed comes from.
Holding j to scroll is the beginner trap. Once hjkl feels normal, use them only for small moves. Bigger jumps are coming up below, and they're what make Vim fast.
## Jump by words and lines
Most of your movement is by word and by line:
w— forward to the start of the next wordb— back to the start of the worde— forward to the end of the word0— the very start of the line^— the first non-blank character (skips the indent)$— the end of the line
server_name example.test; 0 ^ w $ (0 is the very first column, before the indent)
Capital W, B and E do the same thing but treat anything without a space as one big word. That's handy for paths and web addresses like /etc/ssh/sshd_config.
Your cursor is at the start of a long line. Which single key jumps to the end of it?
PermitRootLogin yes # TODO: turn this off ^ cursor
## Jump around the whole file
gg— first line of the fileG— last line of the file42Gor:42— line 42 (great when an error message says "line 42")Ctrl-d/Ctrl-u— half a page down / up%— jump to the matching bracket:(),{},[]
Counts work almost everywhere. Put a number first and Vim repeats the move: 5j goes down five lines and 3w goes forward three words.
You're deep in a 900-line log file. Jump to the very first line.
A config check says: "syntax error on line 42." Jump straight there.
## Start typing in the right place
There's more than one way into Insert mode, and picking the right one saves you a move:
i— insert before the cursora— insert after the cursor (append)I— insert at the start of the lineA— insert at the end of the lineo— open a new line below and start typingO— open a new line above and start typing
A common edit is adding a semicolon to the end of a line. The slow way is $, then a, then typing the semicolon. The Vim way is A and then the semicolon. That's one key instead of two, and it works from anywhere on the line.
You want to add a new rule on the line below the cursor and start typing it. Which key?
-A INPUT -p tcp --dport 22 -j ACCEPT ^ cursor (add a rule underneath)
The cursor is in the middle of a line that's missing its closing semicolon. What's the fastest way to add it?
## Write it down
Keep a tiny cheat sheet with only the keys you're learning this week. Five keys you actually use beat a poster of a hundred you don't. Add a key when the old ones feel automatic.