UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
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.
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.
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.
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 |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.