Reputation: 8582
Sorry for the bad english, see this example:
original
a
line01
line02
line03
line04
b
want to become:
a
line01
line01
line02
line02
line03
line03
line04
line04
b
a
and b
are irrelevant.
I can copy one line and paste, and repeat. Is there any simple solution? like one command?
Upvotes: 3
Views: 287
Reputation: 45087
For funsies a sed
solution:
$ sed 'p' input.txt > output.txt
Using filter, :!
, inside of Vim:
:%!sed p
Obligatory awk solution: awk '1;1' input.txt > output.txt
.
Upvotes: 0
Reputation: 599
You could also write a vim macro-
With your cursor at line 0, column 0; record a macro, store in register a
qa
Copy the current line; paste it below; move your cursor down to the next line
yypj
Save the Macro
q
Now run the a
macro N number of times (it will stop at the bottom of the file regardless)
3@q
Upvotes: 1
Reputation: 58431
Using a global command, this could easily be done like this
:g/^/t.
Breakdown
:g start a global command
/^ search for a begin of line (every line matches)
/t. copy the current line
Upvotes: 4