Search code examples
vimputty

How to copy multiple lines and paste multiple times under each line separately?


original below. I want to copy each line and paste multiple n times under their own lines separately.

USD
XYZ
ABC
YUT
LMO
.
.
. upto so on

want them to become like this. Any way how can I achieve following in Vim?

USD
USD
USD
USD
USD
USD
XYZ
XYZ
XYZ
XYZ
XYZ
ABC
ABC
ABC
ABC
ABC
YUT
YUT
YUT
YUT
YUT
LMO
LMO
LMO
LMO
LMO
.
.
. upto so on

Solution

  • One option is to a find/replace on your entire file

    %s/.*/&\r&/gc
    

    Breakdown

    %s    start a substitute on the entire file
    .*    capture the entire line to be replaced
    &\r&  replace with the entire captured group. Add \r& as amount of required duplicates