Marks — bookmarks for your buffer
A mark is a labeled position you can jump back to. ma sets mark a at the cursor; 'a jumps to that line; ` + a jumps to the exact column. Lowercase marks (a–z) are local to the file; uppercase marks (A–Z) are global, useful for "jump-back-to-this-file-anywhere."
The marks Vim sets for you
` + .— last edit position. (Hugely useful — "take me back to where I was just typing.")` + ^— last Insert-mode position.` + [/` + ]— start / end of the last change or yank.` + </` + >— start / end of the last visual selection.` + '— last jump position (``works as toggle).
Macros — record and replay
A macro is a recorded sequence of keystrokes saved to a register. Press q + a register letter to start recording, do your edit, press q again to stop. Replay with @a, or @@ to replay the last macro. 10@a replays 10 times.
The macro recipe that always works
- Position the cursor at the start of a line.
- Start recording:
qa. - Do all the editing for one line, then end with
j(ornafter a search) so the cursor lands on the next target. - Stop recording:
q. - Replay:
@afor one more,100@afor everything below.
Macros are dot on steroids. The dot command repeats one change. A macro repeats an entire sequence of changes plus the navigation between them. When the dot formula isn't enough — when you need a multi-step transform — record a macro instead.
Registers — Vim's many clipboards
Vim doesn't have one clipboard; it has dozens. Each register is named by a single character. Yanking with "ay puts the text in register a; pasting with "ap retrieves it. Some registers are special:
""— the unnamed register (default for d/y/c/p)."0— the yank register; contains your last yank only (deletes don't touch it). Pasting from"0pgets your last yank back even if you've deleted stuff since."+— the system clipboard (Cmd+C / Ctrl+C territory)."*— the X11 selection clipboard (the middle-click one on Linux).".— last inserted text.":— last command-line."/— last search pattern."_— the black hole (writes go nowhere — useful for deleting without overwriting your yank).