Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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

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

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.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top