Operating System - Linux
1747982 Members
4591 Online
108756 Solutions
New Discussion юеВ

copy and paste from one file to another opened in vi simultaneously

 
SOLVED
Go to solution
Shivkumar
Super Advisor

copy and paste from one file to another opened in vi simultaneously

Hi,

I need to open 2 files and edit them simultaniously in vi.

What are the sequence of commands i need to perform to copy/cut and paste from one file to another ?

Thanks,
Shi
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: copy and paste from one file to another opened in vi simultaneously

Hi Shiv:

Position your cursor in file-1 where you want to paste file-2. Type:

:r file-2

...and file-2 will be copied into file-1.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: copy and paste from one file to another opened in vi simultaneously

Are you talking about copying your text with the mouse buttons? Or using vi's yank buffers?

For the former, I just copy then paste. The buttons depend on which terminal emulator you are using.

For vi, you must have both files on the command line, yank into a named buffer, "a then a yank command. ("a5Y will yank 5 lines into buffer a.) Then you use :n or :rew to go to the other file and use "ap to do a put.
Bill Hassell
Honored Contributor

Re: copy and paste from one file to another opened in vi simultaneously

And one important setting. The default stty values does not include an important value for pasting large amounts of data. It is the ixoff option. Even though you are probably using a LAN connection, stty values do configure the connection. This is recommended for all machines:

stty erase "^H" kill "^U" intr "^C" eof "^D" -parity ixoff

The ixoff tells the connection to pause when data is arriving too fast. Without ixoff, slow machines (especially less than 100 Mhz) will drop lines of text when you are pasting a lot of data.


Bill Hassell, sysadmin
Hein van den Heuvel
Honored Contributor

Re: copy and paste from one file to another opened in vi simultaneously

Bill,

I appreciate the settings advice, but best I can tell is has nothing to do witht he question on hand. The cut & paste discussed is the desirable one, within the same program. Terminal/network IO is only used to display the result, not to perform the atual copying.

Just an observation,
Cheers,
Hein.
Dennis Handly
Acclaimed Contributor

Re: copy and paste from one file to another opened in vi simultaneously

>Hein: but best I can tell is has nothing to do with the question on hand.

I don't see why not. That's why I gave two answers. If I do "opened in vi simultaneously", I would have two windows and use the mouse.

>Terminal/network I/O is only used to display the result, not to perform the actual copying.

(I assume you meant pasting not copying?) Not true. I've have seen users that have problems pasting mass quantities. While I use hpterm and don't seem to have any problems. I also have ixoff set.

So Bill's comments may be useful.

Hein van den Heuvel
Honored Contributor

Re: copy and paste from one file to another opened in vi simultaneously

Dennis, You are correct.

I read the question as :

"copy and paste from one file to another opened in vi simultaneously ... in the same vi session"

That's the only proper way to do it, but it is not too often used

Shi may have referring to two seperate windows, each with a vi session. In that case the terminal settings can become important. However, the 'sequence of [vi] commands' suggest to me that intend is nto to use a terminal emulator / windows-system buffer but either a vi internal buffer or a temporary file.

Cheers,
Hein
Yogeeraj_1
Honored Contributor

Re: copy and paste from one file to another opened in vi simultaneously

hi,
Just on quick observation.

As per Dennis post, since if we want to do a CUT and PASTE, the strokes would be:

"a5dd : will cut 5 lines and put into buffer a

:w : save current file

:e : edit where we wish to insert the lines

"ap : Paste the lines at the current cursor position


hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)