start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 30.4 Editing Multiple Files with vi Chapter 30
vi Tips and Tricks
Next: 30.6 Local Settings for vi and ex
 

30.5 Edits Between Files

When you give a yank 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 (30.4). 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 example illustrates how to transfer text from one file to another.

KeystrokesResults
"f4yy
 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

Yank four lines into buffer f.

:w
 "practice" 6 lines 238 characters

Save the file.

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

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

"fp
 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,

Place yanked text from named buffer f below the cursor.

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, JP


Previous: 30.4 Editing Multiple Files with vi UNIX Power ToolsNext: 30.6 Local Settings for vi and ex
30.4 Editing Multiple Files with vi Book Index30.6 Local Settings for vi and ex

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System