49

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.

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92

2 Answers2

75

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
Birei
  • 35,723
  • 2
  • 77
  • 82
32

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

Mariano Anaya
  • 1,246
  • 10
  • 11
  • 2
    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 x`p` times (where `x` is the number of times you want to paste, and `p` is the paste operation) – Ayush Mandowara Nov 25 '20 at 16:04