brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: "0p in Vim pastes what you yanked, even after deleting

Vim
~/tips/tip-vim-yank-register-0

"0p

Pastes your last copy even after a delete replaced it.

Yank a line, delete some other text, press p, and you paste the deleted text instead of your copy. Every Vim user runs into this.

The reason is that d, c and x also fill the unnamed register that p uses. Your yank is not lost, though. Register 0 holds the last yank and only yanks change it:

"0p

So yy on a line, dd somewhere else, and "0p still pastes the line you copied. It shines when replacing several words with the same text: yank once, then ciw and Ctrl-r 0 in insert mode at every spot.

Deleted text goes into registers 1 to 9, newest first, when you delete whole lines or across lines. So "1p is your last deleted line and "2p the one before. Small deletes within a line go to "-.

To see what is in every register:

:registers

A delete you never want to keep can go into the black hole register, "_dd, which leaves the unnamed register alone. That is handy, but I find "0p easier to remember after the fact.

Further reading: Vim help: numbered registers

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link