Paste multiple times in Vim
Asked Answered
H

3

51

This maybe really simple, But I tried searching and I ended up with stuff like copying multiple lines, cut and paste multiple lines etc. What am looking for is pasting a single line multiple times in Vim.

For eg. A line 'X' is copied and I want to paste this line alone for say 30 times, thus I will have 30 'X' lines. Is it possible with a single command in Vim? Please help me.

Note: A single command for paste. Copy of the line can be done by 'y'. for pasting 30 times or so, I need a single command. Please help me here.

Hyrax answered 22/5, 2013 at 20:26 Comment(0)
T
77

Yes. Put before the command the number of times you want to repeat the action. And this works with many of vim commands. It would be:

30p
Thaxter answered 22/5, 2013 at 20:28 Comment(0)
P
33

In order to copy a line and paste it 30 times, first place the cursor on the line you want to copy, and then:

yy
30p

This will copy the line and paste it 30 times below it. If you want them in another place, then set the cursor to it, and do the 30p part

Pulsatory answered 22/7, 2014 at 22:55 Comment(1)
Just to add, you need not limit yourself to a single line. You can copy a set of lines (for example using Visual Selection and then pressing y) and doing the paste operation xp times (where x is the number of times you want to paste, and p is the paste operation)Mothy
S
0

Suppose you want to copy "n" lines and paste "m" times into the same file. Then open the file using Vim -

  1. Move the cursor to the line from which you want to copy
  2. If you want to copy 543 lines then enter 543yy then you should observe 543 lines yanked at the bottom of the Vim editor
  3. To paste the lines 70 times then enter 70p
  4. To save the changes and quit the Vim editor then enter :wq
Superheterodyne answered 28/2, 2024 at 6:7 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.