Xref: utzoo comp.editors:2648 alt.sources:3425 Path: utzoo!utgpu!cs.utexas.edu!uwm.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!crdgw1!uunet!mcsun!ukc!acorn!unipalm!ian From: ian@unipalm.uucp (Ian Phillipps) Newsgroups: comp.editors,alt.sources Subject: Re: Vi/Ex: command line editor? - Yes! Message-ID: <1991Mar6.145534.14349@unipalm.uucp> Date: 6 Mar 91 14:55:34 GMT References: <1991Jan30.175602.400@convex.com> <4748@male.EBay.Sun.COM> <5104@lure.latrobe.edu.au> <2797@wn1.sci.kun.nl> Organization: Unipalm Ltd., Cambridge, England Lines: 62 Followups-to: comp.editors hansm@cs.kun.nl (Hans Mulder) writes: >In article <5104@lure.latrobe.edu.au> ECSGRT@lure.latrobe.edu.au (GEOFFREY TOBIN, ELECTRONIC ENGINEERING) writes: >> :.,.+3s/some long expression/another long expression/g... >> OOPS! I mistyped something. >> :BORING REPETITION WITH A ONE-CHARACTER CORRECTION >>Command line editing for ex? >Would be a great idea. Definitely. The following works with the C-shell. It was posted about two years ago on Usenet, and the poster then said that its origin was lost in the mists of time. Here goes: You need an alias in your normal setup, thuswise: alias r source ~/cmd/redo Type "r" and you'll be in "vi" open mode, editing the last command. You can use any vi/ex commands (even go into visual mode): when you hit Return, the current line will be executed by the C shell. The "redo" file is as follows. **IMPORTANT NOTE** To avoid mangling in the posting, I've replaced a Carriage Return with "^M" and an ESC with "^[" in ex's "map" command: ----cut here and replace control characters--- # Edit history list at line containing last command (open mode). # Get up to 22 most recent commands. # To work properly, put in .login: alias r source /usr/local/bin/redo # Author unknown. history -h 22 >! /tmp/redo.$$ # Make CR map to :wq! and start ex quietly at 2nd to last line in open mode. ex - '+map ^M :.wq\!^[|set redraw|$-1 open' /tmp/redo.$$ # Insert into history without executing. source -h /tmp/redo.$$ # Clear out temporaries. /bin/rm -f /tmp/redo.$$ # If thing chosen to redo is the redo alias itself then DON'T redo it. if (!-2:0 != !!:0) !! ----cut here---- This works quite well with Sun's csh (which presumably is the original, given who wrote csh :-) but doesn't quite manage it with some imitiations, e.g. Interactive Unix V.3 . Even on the Sun it exposes a csh bug: if the redone command is an alias, csh will moan that it can't find the command. Doing a manual "!!" after that will work fine. Method (2): using "vi" as a command shell: My copy of vi will accept a map entry of the form: :map #n ms"syy@s`s This will cause the current line to be read as a "vi" command: if that command is ":r! ...", then you'll read in a unix command. I have this as a permanent map entry! Ian --- What *is* a .signature file?