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

How do I access previous deletions from the numbered registers?

Answer

"1p through "9p

Explanation

Registers 1-9 contain the last 9 deletions or changes that are at least one line long. This gives you a deletion history.

How it works

  • "1 contains the most recent deletion (one line or more)
  • "2 contains the second most recent
  • Up to "9 which contains the 9th most recent
  • Each new line-or-more deletion shifts the previous ones down

Example

You delete three different lines with dd. Now:

  • "1p pastes the most recently deleted line
  • "2p pastes the second-to-last deleted line
  • "3p pastes the third-to-last

Tips

  • Small deletions (less than one line) go to the "- register instead
  • "1pu.u.u. lets you cycle through registers: paste "1, undo, paste "2, etc.
  • After "1p, the . command advances to the next register
  • This is useful for recovering accidentally deleted text
  • :reg 1 2 3 shows the first three numbered registers

Next

How do you yank a single word into a named register?