vi - Any way to delete in vim without overwriting your last yank?

ID : 10326

viewed : 29

Tags : vimvivimvi

Top 5 Answer for vi - Any way to delete in vim without overwriting your last yank?

vote vote


Pass to the _ register, the black hole.

To delete a line without sticking it in the registers:


See also :help registers.

It's probably safest, if you want to paste something over and over again, to yank it into a "named" register.


Yanks a line into the a register. Paste it with "ap.

vote vote


Your yanked line should still be in the register 0. So do


to paste the line (and delete whenever you want)

vote vote


All yank and delete operations write to the unnamed register by default. However, the most recent yank and most recent delete are always stored (separately) in the numbered registers. The register 0 holds the most recent yank. The registers 1-9 hold the 9 most recent deletes (with 1 being the most recent).

In other words, a delete overwrites the most recent yank in the unnamed register, but it's still there in the 0 register. The blackhole-register trick ("_dd) mentioned in the other answers works because it prevents overwriting the unnamed register, but it's not necessary.

You reference a register using double quotes, so pasting the most recently yanked text can be done like this:


This is an excellent reference:

vote vote


another possibility is:

yank your lines like you would do normally

go to where you want to paste them, enter visual line mode (V)

select the lines you want to replace

hit p to paste your lines.

this also has the added benefit, that the buffer is "swapped" with the replaced contents

vote vote


I use the following mapping to make deleting to the black hole register a bit easier:

nnoremap R "_d 

This way, dd becomes Rd and d$ becomes R$. Note that R is normally bound to enter replace mode, but I found that I never used that, so it was the easisest to remember key for a "really remove" feature.

Top 3 video Explaining vi - Any way to delete in vim without overwriting your last yank?