Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!lll-lcc!qantel!hplabs!pyramid!decwrl!amdcad!cae780!leadsv!esl!mac From: mac@esl.UUCP (Mike McNamara) Newsgroups: net.sources.d Subject: Re: Piping to vi Message-ID: Date: Mon, 15-Sep-86 19:36:47 EDT Article-I.D.: esl.304 Posted: Mon Sep 15 19:36:47 1986 Date-Received: Fri, 19-Sep-86 22:01:34 EDT References: Reply-To: mac@esl.UUCP (Mike McNamara) Organization: ESL, Inc., Sunnyvale, CA. Lines: 78 In article 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 /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| ------------------------------------+-----------------------------------------+