Thursday, March 30, 2006

VI COPY FILE TO FILE

VI COPY FILE TO FILE

Here is how to copy the required number
of lines from one file to another in
VI editor. First use the following
key combinations in the source file.

Press ESCAPE
Press Shift "(Shift double quotes)
Press a
Press the number of lines you want to copy
press y followed by another y

Now press " : " (COLON) to get the vi prompt.
Hit e "Destination file name"
Once you enter the Destination file
go to the line where you want the lines
copied to be inserted.

Press ESCAPE.
Press SHIFT "(Double quotes).
Press a.
Press p.

The lines get copied.

5 comments:

Amit said...

really helpful

thanx :)

Anonymous said...

beautiful! This just saved me a TON of aggravation!

j

Tejas said...

Or do

ESCAPE
v
(select the block you want to operate on)
y
: e [file name]
(go to the position you want to copy to)
p


This is done in Visual mode and saves you counting lines and allows you to select block gedit style.

Amarnath said...

very cool

Abhishek Inani said...

In escape mode run following

:1,450w newfile

Will copy from line 1 to line 450 into filename newfile