Operating System - HP-UX
1833738 Members
2386 Online
110063 Solutions
New Discussion

Re: editing between two files in vi

 
SOLVED
Go to solution
Hanry Zhou
Super Advisor

editing between two files in vi

I want to make editing between two, or more files in vi, how do I do
that? ex, I want to yank a line in file1 and paste it into another file withing the same vi editor.

Has to be able to switch back and forth between these files without
getting
out of vi.

Thanks in advance!
zhou
none
3 REPLIES 3
Paul Sperry
Honored Contributor

Re: editing between two files in vi

why not just open up two hpterms with a vi session in both? Copy and past would be very easy this way.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: editing between two files in vi

Probably the best "vi" like answer is to download and install vim. It's a vi superset and will handle multiple windows.
http://gatekeep.cs.utah.edu/hppd/hpux/Editors/vim-6.1/

Plain vi can also hadle your request:

In File A:

:set number
This will display lines numbers. Let's assume that your want 50 lines beginning at line 50 AND 10 line starting at line 113 to copy into FileB.

1) position the cursor on line 50

"a50yy

50 lines "yanked into buffer "a"

2) position the cursor on line 113
"b10yy

10 lines yanked into buffer "b"

3) :e! FileB

You are now editing FileB

4) Position the cursor where you want the 50 lines inserted

"ap

5) Position the cursor where you want the 10 lines in buffer "b" inserted.

"bp

6) :set nonumber
Turns off line numbering.
If it ain't broke, I can fix that.
S.K. Chan
Honored Contributor

Re: editing between two files in vi

Assuming 2 files (test and test2).
$ vi test
Within vi do ..
:e test2
and that brings up the 2nd file. To switch between these 2 files within vi do use the SHIFT+CTRL and ~ key. For example to switch back to test press and hold SHIFT and CTRL then hit ~.
Now in file test bring your cursor to the line you want to yank. Enter ..
:. y b
That copy the current line to buffer b. Switch to file test2, bring your cursor to the desire line and enter ..
:pu b
which will copy that line over to test2 (below where your cursor's at).