tags:

views:

258

answers:

7

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?

Thanks!

Ted

+25  A: 

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.

dash-tom-bang
Hah, didn't know about the black hole register. Thanks for the enlightenment.
DarkDust
The black hole register is way to go here, but I sometimes find: Vp a good alternative as it is shorter. Note that the unnamed register will be filled with the previously selected text.
Peter Rincker
+1 for mentioning the blackhole register.
jeffjose
+1  A: 

You could use buffers: "<character><command>

E.g.:

"ayy (move) dd"aP

Or:

yy (move) "addP

DarkDust
+1  A: 

For your specific question, as asked, couldn't you just swap the order of the last 2 steps?

  • yank line (same)
  • move to new location (same)
  • paste yanked line (was step 4)
  • delete line you don't want (was step 3)

Granted, I usually use a named register for this type of thing, but sometimes the solution is simpler than what first comes to mind.

Dan
+2  A: 

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.

Jörn Horstmann
+4  A: 

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

knittl
A: 

You may also try out the following script: http://www.vim.org/scripts/script.php?script_id=2703

d.m
+2  A: 

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

"0p

to paste the line (and delete whenever you want)

mb14