How do I cycle through numbered registers to find a previous deletion?
Answer
"1pu.u.u.
Explanation
Vim stores the last 9 deletions in numbered registers 1-9, with the most recent in register 1. The special u. (undo-repeat) pattern lets you cycle through them: paste from register 1, undo, and dot-repeat automatically advances to register 2, then 3, and so on.
How it works
"1p— paste from register 1 (most recent delete)u— undo the paste.— repeat the paste, but Vim automatically advances to the next register- Each
.afterutries register 2, then 3, etc. - When you see the text you want, stop pressing
u.
Example
After several deletions:
"1 = last deleted text
"2 = second-to-last
"3 = third-to-last
...
"9 = ninth-to-last
Sequence:
"1p → pastes register 1
u. → replaces with register 2
u. → replaces with register 3
(stop when you find what you need)
Tips
- Small deletes (less than a line) go to the
"-register, not the numbered ones - The numbered registers are a stack: new deletes push old ones up
- Use
:registers 0123456789to preview all numbered register contents - Register 0 always holds the last yank (not affected by deletes)