vimtricks.wiki Concise Vim tricks, one at a time.

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:

  1. Shifts the content of "1 → "2, "2 → "3, ... "8 → "9 (oldest delete is discarded)
  2. 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:

  • "1p pastes line C
  • "2p pastes line B
  • "3p pastes 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, so p and "1p paste the same thing after a linewise delete
  • After yanking (not deleting), "0 holds the yanked text and "1 is not overwritten — use "0p to paste a yanked line even after subsequent deletes
  • Use :registers to inspect all register contents at once and identify which number holds the text you need

Next

How do I enable matchit so % jumps between if/else/end style pairs?