UNIX Hints & Hacks

ContentsIndex

Chapter 8: Editors

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

8.1 The Anatomy of ed & vi

 

8.5 Abbreviating vi Commands

 

 

8.2 The Six Steps to ed

 

8.6 Creating Macros

 

8.10 Edit, Run, and Edit Again

 

8.3 Six Simple Steps to vi

 

8.7 Search and Replace

 

8.11 Reading STDOUT into vi

 

8.4 Configuring vi Parameters

 

8.8 Other Places to Use vi

 

8.12 Using vi when tmp Is Full

 

 

8.11 Reading STDOUT into vi

8.11.1 Description

8.11.1 Description

There are several ways to get the results of a command from within vi to be read into the session that you are working in.

Example One: Reading the Execution

This form of reading a system command that is executed can all be done in one step. It is the shortest method of the three possible ways to perform this function.

:r! date

By using the command line mode, you can tell the editor to read the output of the execute command into the editor to the current position of the cursor.

Example Two: Cut-and-Paste

If you access the vi editor from a window off your desktop, you can execute ( !) a command from the command line mode ( :) and the results are displayed on the bottom of the screen. This result is not part of the file that you are editing, merely temporarily displayed until you type the Enter key.

:!date
Mon Jan  4 03:26:40 EST 1999
[Hit return to continue]

You can cut the results with your mouse and paste it into the file you are working on in insert mode.

Example Two: Write/Read A File

This method is a two-step process, but you don't have to be accessing a vi session from within a window off the desktop of your workstation. This can be done from any terminal. When you go into the command line mode, you can execute the command and write the results out to a file such as

:!date > /tmp/date.tmp

The date command gets executed ( !) and the output is written ( >) to the file /tmp/date.tmp. Then position the cursor where you want the results of the date command to go.

:r /tmp/foo

Execute the read ( r) command on /tmp/dat.tmp and the data is read to the location of the current cursor position. Throughout the process you will never see any output until the file is actually read into the editor.

UNIX Hints & Hacks

ContentsIndex

Chapter 8: Editors

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

8.1 The Anatomy of ed & vi

 

8.5 Abbreviating vi Commands

 

 

8.2 The Six Steps to ed

 

8.6 Creating Macros

 

8.10 Edit, Run, and Edit Again

 

8.3 Six Simple Steps to vi

 

8.7 Search and Replace

 

8.11 Reading STDOUT into vi

 

8.4 Configuring vi Parameters

 

8.8 Other Places to Use vi

 

8.12 Using vi when tmp Is Full

 

 

© Copyright Macmillan USA. All rights reserved.