From: kathyj@pyramid.COM (Kathy Johnson )
Newsgroups: comp.unix.questions
Subject: Re: vi (cut and paste)
Keywords: vi
Date: 31 Aug 92 20:04:21 GMT
Distribution: usa
Organization: Pyramid Technology Corporation, Mountain View, California

In article <1992Aug25.035349.6759@uxa.ecn.bgu.edu>, mflll@uxa.ecn.bgu.edu (Dr. Laurence Leff) writes:
|> I have prepared some Helpful Hint files on common problems of moving
|> text around from file to file or within a file.  Perhaps, they may  
|> be helpful.  Thus, I post the three files here.  Enjoy.
|> 
|> These were posted and made available on this machine for all to use.
|> 
|> 
|> Dr. Laurence Leff  Western Illinois University, Macomb IL 61455 ||(309) 298-1315
|> Stipes 447 Assistant Prof. of Computer Science ||Pager: 837-5909 FAX: 298-2302
|> Moderator:  Symbolic Math List, Technical Reports List||mflll@uxa.ecn.bgu.edu 
|> alt.binaries.pictures.fine-art hierarchy          ||BITNET: mflll@ecnuxa.bitnet
|> ______________________________________________________________________
|>             How to Move Text from One File to Another in VI
|> 
|> Frequently, a question arises, how do I move a block of text from
|> file1 to somewhere  within file2.  This note will give you one way
|> of performing this task using the vi editor.
|> 
|> For example, you may have a procedure defined in file1 and you would
|> like to make use of it in a program contained in file2.
|> 
|> file1 and file2 refer to arbitrary file names.  Substitute the names
|> of the source file containing the text you want to copy for "file1"
|> in the instructions below and the name of the target file where
|> you want to copy the stuff into "file2"
|> 
|> This will consist of starting file1 up with vi, copying the block
|> of text to a temporary file.  Then you will read the temporary file
|> into the appropriate location in file2.
|> 
|> 1. Get into file1 by typing "vi file1"
|> 
|> 2. Move the cursor to the first line in the region to be copied.
|> 
|> 3. Press "ma"
|> 
|> 4. Move the cursor to the last line (bottom line) of the region to
|>    be copied.
|> 
|> 5. Type the following sequence of characters
|>    :'a,.w /tmp/xxx
|> 
|>    You may use any name you want instead of xxx
|> 
|>     The machine will display a message at bottom of screen beginning
|>     with "/tmp/xxx" [New file]
|>    and then tell you how many lines and chars you put in this temporary
|>     file.
|> 
|> 6. Leave vi.  You can use the sequence ":wq" for this purpose.
|> 
|> 7. Now get into file2 by typing "vi file2"
|> 
|> 8. Move the cursor to the line just before you want to add the
|>    text
|> 
|> 9. Type the following sequence of characters
|>    :r/tmp/xxx
|> 
|> All done!
|>
Here is a quicker way to move a block of text from file1 to file2:

1.  Get into file1 by typing "vi file1"
2.  Move the cursor to the first line in the region to be copied.
3.  Press "ma"
4.  Move the cursor to the last line (bottom line) of the region to be copied.
5.  Type the following sequence of characters
	"By'ay
     You may substitute another letter for the buffer name  (B in the sample)
6.  Do not exit vi.  Open the other file by typing the following sequence of
    characters:
	:e file2
7.  Move the cursor to the line you wish to place the text AFTER.
8.  Type the following sequence of characters:
	"Bp
    If you used a different buffer name replace B with the buffer name you used.

It's only a little shorter but saves going in and out of vi.

Have fun,

Kathy Johnson

-- 
Lost:  One clever .sig file.  Short, witty and sweet.  Reward.
       Does not bite.

       kathyj@pyramid.