Reputation: 30105
If I have something selected in Vim in visual mode, how can I duplicate that selection and place it below or above the selection?
Upvotes: 17
Views: 9701
Reputation: 2177
Do you want to copy/paste the whole line? If so, get out of visual mode, then use yy to yank the whole line, then p to paste.
Upvotes: 0
Reputation: 19873
Use y to yank (copy) the selection into a buffer.
Use p to paste the selection where you want it to be.
Upvotes: 1
Reputation: 87260
You have two options:
Upvotes: 0
Reputation: 11847
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 you're doing this a lot.
Upvotes: 8
Reputation: 182880
Press y to yank what you've got selected visually, then p to paste below the cursor or P to paste above it.
And since you asked about pasting below the selection block, I'll copy what michael said below: After you y to yank, use '> to move it to after the selection block, and then p to paste.
Upvotes: 33
Reputation: 5051
Since I do this a lot (select a block, yank, go to end of last visual selection, paste) I set up a visual block shortcut under CTRL+P (prior to this, CTRL+p seems to be the same as j in a visual block).
vmap <C-p> y'>p
Now it's just making a visual selection and pressing CTRL+p.
Upvotes: 11