ian@unipalm.uucp (Ian Phillipps) (03/06/91)
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?
fisher@inls1.ucsd.edu (Yuval Fisher) (03/11/91)
I find that ex Version SVR3.1 (released with sunOS 4.1.1, I am guessing) and ex Version 3.7, 6/7/85. (released with previous sun systems) behave differently with the "-" option. The latter does what I would reasonably expect from the man pages explanation, but the first causes the terminal output to be somewhat non-sensical. This causes a bit of a problem with the redo script recently posted to edit the last command. It works beautifully with Version 3.7; not at all with Version SVR3.1 if the "-" option is included; and so-so with Version SVR3.1 if the "-" option is removed. Does some vi/ex guru know what I am talking about and why it is so and if there is a fix ? Buckets of thanks, Y. Fisher