Unix Power ToolsUnix Power ToolsSearch this book

17.4. Edits Between Files

When you give a yank buffer (temporary holding buffer) a one-letter name, you have a convenient way to move text from one file to another. Named buffers are not cleared when a new file is loaded into the vi buffer with the :e command (Section 17.3). Thus, by yanking (copying) or deleting text from one file (into multiple named buffers if necessary), calling in a new file with :e and putting the named buffer into the new file, you can transfer material between files.

The following table illustrates how to transfer text from one file to another. Type the keystrokes exactly as shown to achieve the stated result.

Keystrokes

Action

Results

"f4yy

Yank four lines into buffer f.

With a screen editor you can scroll
the page, move the cursor, delete lines,
insert characters, and more, while seeing
the results of the edits as you make them

:w

Save the file.

"practice" 6 lines 238 characters

:e letter

Enter the file letter with :e. Move cursor to where the copied text will be placed.

Dear Mr.
Henshaw:
I thought that you would
be interested to know that:
Yours truly,

"fp

Place yanked text from named buffer f below the cursor.

Dear Mr.
Henshaw:
I thought that you would
be interested to know that:
With a screen editor you can scroll
the page, move the cursor, delete lines,
insert characters, and more, while seeing
the results of the edits as you make them
Yours truly,

If you yank into a buffer and type the buffer name as an uppercase letter, your new text will be added to the text already in the buffer. For example, you might use "f4yy to yank four lines into the buffer named f. If you then move somewhere else and type "F6yy with an uppercase F, that will add six more lines to the same f buffer -- for a total of ten lines. You can yank into the uppercase buffer name over and over. To output all of the yanked text, use the lowercase letter -- like "fp. To clear the buffer and start over, use its lowercase name ("fy...) again.

-- LL and JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.