Lesson 8.3: Working efficiently in Vim
Vim's grammar of operators and motions, counts (3dd, 5j), jumping (gg, G, :N, line numbers), searching with / and n, copying and pasting lines (yy, p), changing a word (cw), substituting across the file with :%s, and choosing your default editor with $EDITOR.
20 min
You will learn to
- Combine operators (d, c, y) with motions (w, $) and counts
- Jump to the first, last or a numbered line and show line numbers
- Search with / and repeat with n
- Copy and paste lines with yy and p
- Replace text in the whole file with :%s/old/new/g
- Set the default editor with EDITOR
Key terms
- Operator
- A verb: d delete, c change (delete and enter insert mode), y yank (copy). Pressed twice (dd, cc, yy) it acts on the whole line.
- Motion
- Where the cursor goes: w next word, b previous word, $ end of line, 0 start of line, gg first line, G last line, /text next match.
- Operator + motion
- An operator followed by a motion acts on the text the motion covers: dw deletes to the next word, d$ to the end of the line, cw changes a word.
- Count
- A number typed before a command repeats it: 3dd deletes three lines, 10j moves ten lines down.
- Register
- Vim's clipboards. Whatever you delete or yank goes into the unnamed register; p pastes after the cursor, P before.
- :s and :%s
- Substitute: :s/old/new/ on the current line, :%s/old/new/g on every line, every match. The pattern is a regular expression.
- EDITOR
- The environment variable programs read to decide which editor to open for you.
← Vim basics: modes, saving and quitting · All lessons · Processes and ps →