0

I'm facing a simple problem with Vim : I would like to copy a word and then cut another to paste the first in the 2nd place

For example :

Platea, integer nisi velit!

I would like to transform it to :

Platea, integer nisi integer!

How can i make it the easiest way ? If i copy integer with y and then cut velit with d i can't copy the first word anymore, the buffer contains velit ...

Xavier
  • 3,919
  • 3
  • 27
  • 55

4 Answers4

4

You can follow these steps:

  • Yank integer (yiw)
  • Visual select velit (viw)
  • Paste (p)

Also try YangRing.vim plugin.

kev
  • 155,172
  • 47
  • 273
  • 272
2

You could try yanking into a register. For example, with the cursor on integer:

"xyiw

Which will yank integer into the x register (arbitrary letter), and then after deleting velit, you can paste using "xp. You can use this with multiple registers as well, so if you need to do an assortment of copy/pastes using the same words in different combinations, it may be useful. I'm sure there will be a more elegant way provided by the Vim gurus, but that should work if you need something to tide you over :)

RocketDonkey
  • 36,383
  • 7
  • 80
  • 84
1

That's "register", not "buffer", :help registers.

Here is a mapping I've had in my ~/.vimrc for a while:

vnoremap <leader>p "_dP

It deletes the selected text into the "black hole" register and puts the content of the unnamed register. Easy.

Another option is to use register zero: "0p.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • I don't really understand your tips. If i understand it right, i have to copy my word --with `ye`, then select in visual mode the 2nd word -- `ve` and `p`. I don't really get the difference btw your solution and the kev's one. – Xavier Nov 20 '12 at 10:14
  • When you paste `aaa` over `bbb`, the unnamed register now contains `bbb` and you can't paste `aaa` again over `ccc`. This tip adresses this issue. But I think that I misread your question. I didn't saw that you were cutting before pasting and that *that* was the issue. Indeed, `viwp` is the right way to "paste over" in Vim. – romainl Nov 20 '12 at 10:31
0

If you add this to your vimrc

xnoremap p "_dP

it will cause pastes in visual mode to delete to the black hole register which will prevent clobbering your yanked content that you wish to paste multiple times.

Bradley Davis
  • 19
  • 2
  • 7