Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy lines into a second file with vi

Status
Not open for further replies.

rondebbs

MIS
Dec 28, 2005
109
US
Hello, until now I have been using vi to access one file at a time. I use the 'yy5' and 'p' to copy 5 lines and paste then some where else in the file. Now I need to copy 5 lines from one file and paste them into a second file.

If I'm editing the hosts file I can edit the hosts.2 file by typing :e hosts2. This takes me to the hosts2 file in vi but I can not figure how to copy 5 lines from hosts to hosts2.

Brad
 
You cannot use the unnamed buffer going from one file to the next. vi clears that buffer when it starts editing the next/new file.

You have to use a named buffer like so:

Code:
esc           (make sure you're in command mode)
              (move to first of the 5 lines you want to copy)
"a5yy         (yank 5 lines into buffer a)
:e otherfile  (start editing otherfile)
              (move to position you want to add the lines below)
"ap           (paste contents of buffer a below current line)

You can also use "aP (paste above current line)


HTH,

p5wizard
 
Excellent it works. Interesting how you use the " character.
 
It's all in the man page. Sort of...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top