Copy lines from one file to another using vi

Using yyp I can copy and paste within the same file.  How can I copy lines of script from one file to another using vi.  
weephAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ilikenineConnect With a Mentor Commented:
Follow the same way as mentioned by tel2 for copying into cuffer and yanking (yy).
Now only problem is swaping between to files.
Do this in vi editor.
:e#
this will easy swap between two files.

to open two files you can say
vi <file1> <file2>

rest is ok i guess..
enjoy ving...
GG
0
 
tel2Commented:
weeph,

Try this example:

file1:
 A
 B
 C

file2:
 D
 E
 F

If you want to copy the E and F lines from file2 to file1, do this:
 vi file1 <Enter> To edit file1
 :e file2 <Enter> To swap file1 to file2
 <down-arrow>     To move the cursor to the "E" line
 "a               To open a buffer called "a" (for example)
 2yy              To copy (Yank) 2 lines to buffer "a"
 Ctrl-A           To swap back to file1
 "ap              To paste from buffer "a" at the current cursor position in file1

NOTE: Once you've made any changes to either file, you have to save then ":w", before you can swap with Ctrl-A.

Let me know how you get on with this.
0
 
weephAuthor Commented:
Hi tel2
Tried your suggestion but all it did was to paste the same lines into file2.  I entered the key strokes as per your instructions saving file using w etc but when i did Ctrl-A it did not swap back to file1

weeph
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
tel2Commented:
weeph,

Let's just try the swapping between files, first.  If we can get that working, we'll move on.  Try this:

vi file1<Enter>   To edit file1
:e file2<Enter>   (that's colon"e" file2) To swap from file1 to file2
Ctrl-A             To swap back to file1
Ctrl-A             To swap back to file2

Does that work?  If yes, the try again on by previous example.  If not, let me know what happened.

NOTE: Ctrl-A means to hold down "Ctrl", then press and release the "A" key (no need to press shift for upper case), then release the "Ctrl" key.

NOTE: In this example, and in my original example, you should NOT need the ":w" (that's colon"w"<Enter>).  That's only required if you want to swap files AFTER making changes to either file.
0
 
weephAuthor Commented:
Hi

No Ctrl+A doen't swap between files
Just beeps at me.  Using SCO 5.0.5 not that it should make any difference
weeph
0
 
tel2Commented:
weeph,

Questions:
1. Does the ":e file2" swap to the file2?
2. How exactly do you do the Ctrl-A (ie: what exact key sequence)?  Sorry if this sounds basic, but I need to know.
0
 
weephAuthor Commented:
Yes :e file2 swaps to file2
Press and hold Ctrl, tap A
weeph
0
 
tel2Commented:
weeph,

Any error message (probably at the bottom of the screen) when it beeps at you when you press Ctrl-A?  If so, what is it?  If not, I think I admit defeat.
0
 
weephAuthor Commented:
No error message sorry
weeph
0
 
weephAuthor Commented:
Works like a charm. Thanx
weeph
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.