[net.sources.d] Piping to vi

jrw@hropus.UUCP (Jim Webb) (09/11/86)

> How many times have you wanted to pipe to vi, but were loath to modify
> the source? Well, I have been using the following shell function for
> some time, and one of my colleagues suggested that the net might be
> interested in it. This can be converted to an alias for the csh; it
> will work as is in the System V.2 Bourne shell, and the Korn shell:
> 
> pvi()
> {
> 	cat > pipe 2>&1 & view $* pipe < /dev/tty
> }
> 
 ...
> 	This is as simple to use as: ls -l | pvi

How about in vi entering:

		:r !ls -l

This runs ls -l and puts the output in the current file.  It obviously
works for any command that writes to stdout...
-- 
Jim Webb             "Out of phase--get help"          ...!ihnp4!hropus!jrw

rjs@cuuxe.UUCP (Richard J. Straka) (09/15/86)

(line eater)

What about performing the following on a blank line:

!!ls -l

Rich Straka     ihnp4!cuuxe!rjs

mac@esl.UUCP (Mike McNamara) (09/16/86)

In article <669@hropus.UUCP> jrw@hropus.UUCP (Jim Webb) writes:
>> How many times have you wanted to pipe to vi, but were loath to modify
>> the source? 
>> pvi()
>> {
>> 	cat > pipe 2>&1 & view $* pipe < /dev/tty
>> }
>> 
> ...
>> 	This is as simple to use as: ls -l | pvi
>
>How about in vi entering:
>
>		:r !ls -l
>
>This runs ls -l and puts the output in the current file.  It obviously
>works for any command that writes to stdout...
>-- 
>Jim Webb             "Out of phase--get help"          ...!ihnp4!hropus!jrw

Well, I hope this doesn't degrade into a "I know more about vi than you do"
contest, but, being a veteran of many such fights, I can offer this:

Use the ! operator.  Basically it executes a shell command on it's
selected range, replacing that range with the output of the command.

To read in the output of a command at the current line, move to (or make)
a blank line, then type:
!!ls -l

!!date is good for marking comments

The reason you move to a blank line is vi sends the current line as input to
the command.  A blank line becomes empty input (actually just \n).

This input & output stuff should give you more ideas:

Reformating commands, like fmt(1), which does simple text rearragement, can
be invoked on a region of text by marking the end of the region (ma) then
moving to the begining, and typing:
!'afmt

Or, as } goes to the end of a section, 
!}fmt

For C hackers, the program cb(1), a C reformatter, can be easily used by
1G!Gcb
which moves you to line one, sends the entire file to cb, then reads in
the standard output of cb in place of the selected region, (which is the entire
file), and leaves you in vi, on the prettied file.  This is analogous to:

:wq
% cb < file.c > /tmp/file.c
% mv /tmp/file.c file.c
% vi file.c

All from within vi; and if you didn't like what happened, the "u" command will
undo it!

!learn !a !new !command !every !day  !

(I just wish range specifications worked on the ~ command....)
Look what I have to use to change the case of a word:
map ^A ea ^M^[k$b~~~~~~~~~~~~~~~~~~~~~~~J^M
Any one have a better way? 
Hmm, just thought of:
map ^A i^M^[ea^M^[k!!tr a-zA-Z A-Za-z^MJkJ
but this invokes a process...
-- 
------------------------------------+-----------------------------------------+
| Michael Mc Namara                 |  MM MM MM    OO   SSS   AAA   II  CCCC  |
| ESL Incorporated                  |   M   M  M  O  O S         A   I C    C |
| ARPA: mac%esl.UUCP@ames.ARPA      |   M   M  M  O  O  SSS   AAAA   I C      |
|       mac%esl.UUCP@shasta.ARPA    |   M   M  M  O  O     S A   A   I C    C |
|       mac%esl.UUCP@lll-lcc.ARPA   |  MM   M  M   OO   SSS   AAA A III CCCC  |
------------------------------------+-----------------------------------------+
| Note: esl used to be called tflop; the path mac%tflop will still work awhile|
------------------------------------+-----------------------------------------+