How do the numbered delete registers work and why does deleted text rotate through registers 1 through 9?
Answer
"1 through "9
Explanation
Vim maintains a rotating history of deleted text across registers "1 through "9. Understanding how this rotation works lets you reliably recover text from earlier deletions — not just the most recent one.
How it works
Whenever you make a linewise or multi-line delete (using dd, D, cc, C, or d{motion} spanning multiple lines), Vim:
- Shifts the content of
"1→"2,"2→"3, ..."8→"9(oldest delete is discarded) - Stores the new deletion in
"1
So "1 always has the most recent big delete, "2 the one before, and so on, back 9 steps.
Small deletes (single characters with x, or inline deletions under one line) do not rotate the numbered registers — they go into "- (the small delete register) instead.
Example
line A ← delete with dd → goes to "1
line B ← delete with dd → pushes A to "2, B is in "1
line C ← delete with dd → pushes A to "3, B to "2, C is in "1
Now:
"1ppastes line C"2ppastes line B"3ppastes line A
To cycle through the history interactively: paste "1p, undo with u, and press . — the dot command increments the register number on each repeat.
Tips
- The unnamed register
""always reflects the most recent yank or delete, sopand"1ppaste the same thing after a linewise delete - After yanking (not deleting),
"0holds the yanked text and"1is not overwritten — use"0pto paste a yanked line even after subsequent deletes - Use
:registersto inspect all register contents at once and identify which number holds the text you need