From: hjiwa@gruc19.nor.chevron.com (Jeff Wang)
Newsgroups: comp.editors
Subject: Re: UNIX COMMAND IN VI SESSION.
Keywords: vi
Date: 5 Oct 92 18:19:19 GMT
Distribution: na
Organization: Chevron

In article <1992Sep30.221957.6250@infonode.ingr.com> "Vilva Natarajan <vilva@madras.b23b.ingr.COM>" writes:
|>Hello : 				OCT-01-92
|>
|>VI allows you to execute UNIX commands in a VI session.
|>How can I enter AT THE CURSER, the output of the  UNIX's  "date" command ?

For inserting the date on a line by itself below the current line...

:r !date

or for replacing the current line with the output from the date command...

:.!date    or    !!date

or for placing the output from any Unix command AT THE CURSOR location,
I like using the two keymaps (with control characters printed out)...

"    !@  --mapto-->  replace "Unixcommand!@" with "Unixcommand" output
map! !@ ^V^V^M@^[bi:r !^[F:"adt@mm@ais^["bd$dd`m@b
"    @@  --mapto-->  replace "@Unixcommand args@@" with "Unixcommand" output
map! @@ ^V^V^M@^[F@s:r !^[F:"adt@mm@ais^["bd$dd`m@b

Entering  !@ or @@  immediately right after  a Unix command  causes the embedded
command to be replaced  by the output  from the command.   The !@  keymap is for
commands that are to be executed without any input arguments.   The @@ keymap is
for commands that use input arguments.   For example, entering the following...

Today's date : date!@

would cause the !@ keymap to change the above line to...

Today's date : Mon Oct  5 12:39:32 CDT 1992

with the cursor left  at the end of the line in input mode.   For either keymap,
the command  may also be embedded  in the middle  of a line.   As an  example of
this using the @@ command, given the following line...

Current Date :   (expires 30 days from the Current Date)

adding the following text in insert mode...

Current Date : @date +"\%b \%d \%Y"@@  (expires 30 days from the Current Date)

will cause the @@ keymap to change the line to ...

Current Date : Oct 05 1992  (expires 30 days from the Current Date)

Also note that  because this keymap uses two characters, whether it works or not
may  depend upon  your 'timeout'  option  setting; i.e., you need  to type  both
characters in either !@ or @@ in close succession.

I also have my "q" key mapped as...

"   q  --mapto-->  copy the directory path and date below the current line
"                  change to your user ID -----V
map q :r !echo `pwd`/% `date +"\%b \%d \%Y"`^M/hjiwa^Md0f i   ^[0

The q keymap  outputs to a line  below the cursor  the directory path, filename,
and current date, an example being...

hjiwa/Test/C/FFT/main.c    Oct 05 1992

I like to "stamp"  various files  with this information.   Change the "hjiwa" in
the keymap to your user ID.


-- 
 #====}==) #===(==}  #====}==) #===(==}  {==)===# (=={====#  {==)===# (=={====#
>> Jeff Wang                             Net   : hjiwa@gruc19.nor.chevron.com <<
>> Chevron Petroleum Technology Company  Profs : hjiwa                        <<
>> Geophysical/Geological Applications   Phone : (504) 592-6162               <<
>> 935 Gravier Street, Room 1006         Fax   : (504) 592-6958               <<
>> New Orleans, Louisiana 70112          Valeo,vales. Die dulci fruimini!! :) <<
>>  "Eenie, meenie, chili beanie, your lucky number is... C!" -- Kelly Bundy  <<
 #===(==}      C ... it's not just a language, it's also a chord.      {==)===#