Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate each line in VI

Tags:

vim

I have a file with these lines:

aa
bb
cc
dd

I want to convert this into:

aa
aa
bb
bb
cc
cc
dd
dd

Is this possible in VI?

like image 286
arunmoezhi Avatar asked Sep 05 '25 16:09

arunmoezhi


2 Answers

Try this simple one:

:g/^/norm yyp

Yet another one(shorter):

:%s/.*/&\r&

Another one:

:%!sed p
like image 170
kev Avatar answered Sep 07 '25 19:09

kev


I like g/^/t.
The g (for global) command will look for any lines that match a pattern.
The pattern we specified is ^, which will match all lines.
t will copy and paste, and finally
the dot tells it to paste below.

Do I win for brevity?

like image 34
dimitriy Avatar answered Sep 07 '25 19:09

dimitriy