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

tedsuo picture tedsuo · Sep 3, 2010 · Viewed 48.3k times · Source

I love vim, but one common gotcha is:

  • yank a line
  • go to where you would like to paste it
  • delete what's there
  • paste your yank, only to discover that it pastes what you just deleted

Obviously the workflow is delete first, yank second. But it would be reeeeeaaaaaalllly nice if I didn't have to. Anyone have a trick for this? Does vim have a paste buffer that works well, or is there a .vimrc setting I can change?

Answer

dash-tom-bang picture dash-tom-bang · Sep 3, 2010

Pass to the _ register, the black hole.

To delete a line without sticking it in the registers:

"_dd

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.

"aY

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