Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim duplicate selection

If I have something selected in Vim in visual mode, how can I duplicate that selection and place it below or above the selection?

like image 877
Gabriel Solomon Avatar asked Apr 08 '09 18:04

Gabriel Solomon


People also ask

How do I select and copy text in Vim?

Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.

How do I copy a chunk of text in Vim?

For copy: Place cursor on starting of block and press md and then goto end of block and press y'd. This will select the block to paste it press p. For cut: Place cursor on starting of block and press ma and then goto end of block and press d'a. This will select the block to paste it press p.


1 Answers

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.

like image 88
Paul Tomblin Avatar answered Sep 18 '22 05:09

Paul Tomblin