Vim — Editing with Verbs and Motions
Anyone can open Vim, type some text and quit. What makes it fast is Normal mode, where short key combinations delete, copy and change whole words or lines without touching the mouse. They are easy to remember, because they're built like tiny sentences.
The rule
Verb then motion: d plus a move deletes that far.
A verb says what to do:
| Verb | Action |
|---|---|
d |
delete (the text is kept so you can paste it) |
y |
yank, which means copy |
c |
change: delete, then drop into Insert mode |
A motion says how far to go. These are the movement keys you already know: w (to the next word), $ (to the end of the line), G (to the end of the file).
Put them together:
dwdeletes to the start of the next word.d$deletes to the end of the line.cwchanges the rest of the current word.yGcopies everything from here to the end of the file.
Typing the verb twice acts on the whole line: dd deletes a line and yy copies one. A number in front repeats: 3dd deletes three lines and 2w jumps two words.
The rest of the everyday toolkit:
| Key | Does |
|---|---|
x |
delete the character under the cursor |
p / P |
paste after / before the cursor |
u |
undo |
Ctrl+r |
redo |
. |
repeat the last change |
/word |
search forward for "word"; n finds the next match, N the previous one |
And one command-line trick: :%s/old/new/g replaces every "old" with "new" in the whole file.