views:

337

answers:

5

If i have something selected in VIM in visual mode .... how can i duplicate that selection and place it below or above the selection.

A: 

Do you want to copy/paste the whole line? If so, get out of visual mode, use

yy

to yank the whole line, then

p

to paste.

Adam Neal
a) he didn't say it was a single line, and b) why get out of visual mode if you've already got it selected?
Paul Tomblin
+1  A: 

use y for yank (copy) the selection into a buffer

the p for paste the selection where you want it to be

Eric
using p for paste breakes the formating because it doesnt take the whole lines
solomongaby
+10  A: 

Just hit 'y' to yank what you've got selected visually, the "p" to paste below the cursor or "P" to paste above.

And since you asked about pasting below the selection block, I'll copy what michael said below: After you y to yank, you '> to move to after the selection block, and then p to paste.

Paul Tomblin
thanks that was what i was looking for. Do you know how i could paste it below ?
solomongaby
A: 

You have two options

  • yy which copies current line, then p to paste
  • make selection (with v for example), then copy with y and paste with p
Darth
using p for paste breakes the formating because it doesnt take the whole lines
solomongaby
+1  A: 

In addition to the V...yp combo you might want to know about some jumps '< and '> to get to the last character of the previous visual mode text. Specifically If you want to paste below you'd go V...y'>p if it's a long multiline it may be handy.

It's one of those jumps you may find handy if your doing this a lot

michael
that doesn't seem to work, do you press ' and then SHIFT+. to get > ?
solomongaby
It works for me.
Paul Tomblin
i am actualy using a VIM plugin for Netbeans so this might be the problem
solomongaby
'> has 'not in vi' in the vim help so you'll be missing out on that one. :helpgrep not\ in\ Vi yields 709 matches in the vim help. So you probably shouldn't confuse the two. Most emulators only cover the basics
michael