Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making each line double vim

Tags:

shell

vim

vi

I have a file which looks like this:

file1
file2
file3
.
.
.
filen

I want to convert it to :

echo "file1"
cat file1
echo "file2"
cat file2
.
.
.
.
echo "filen"
cat filen

One way can be to have a for loop and read the content of original file and write modified content to another file , I did that and it worked. Is there any command to do the same in vim through :g or any other command?

like image 658
nav_jan Avatar asked Dec 16 '22 22:12

nav_jan


1 Answers

Try this:

:%s/.*/echo "\0"\rcat \0/g

Explanation:

:%s/a/b/g means search whole file and replace a to b.

.* means match every thing in one line.

\0 means the matched thing.

\r means the new line.

like image 101
xdazz Avatar answered Dec 21 '22 09:12

xdazz