home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3009 < prev    next >
Encoding:
Internet Message Format  |  1991-03-07  |  2.4 KB

  1. From: ian@unipalm.uucp (Ian Phillipps)
  2. Newsgroups: comp.editors,alt.sources
  3. Subject: Re: Vi/Ex:  command line editor? - Yes!
  4. Message-ID: <1991Mar6.145534.14349@unipalm.uucp>
  5. Date: 6 Mar 91 14:55:34 GMT
  6.  
  7. hansm@cs.kun.nl (Hans Mulder) writes:
  8.  
  9. >In article <5104@lure.latrobe.edu.au> ECSGRT@lure.latrobe.edu.au (GEOFFREY TOBIN, ELECTRONIC ENGINEERING) writes:
  10. >>  :.,.+3s/some long expression/another long expression/g...
  11. >>    OOPS!  I mistyped something.
  12. >>  :BORING REPETITION WITH A ONE-CHARACTER CORRECTION
  13. >>Command line editing for ex?
  14.  
  15. >Would be a great idea.  Definitely.
  16.  
  17. The following works with the C-shell. It was posted about two years ago
  18. on Usenet, and the poster then said that its origin was lost in the
  19. mists of time. Here goes:
  20.  
  21. You need an alias in your normal setup, thuswise:
  22.  
  23.     alias r source ~/cmd/redo
  24.  
  25. Type "r" and you'll be in "vi" open mode, editing the last command. You can
  26. use any vi/ex commands (even go into visual mode): when you hit Return, the
  27. current line will be executed by the C shell.
  28.  
  29. The "redo" file is as follows. **IMPORTANT NOTE** To avoid mangling in
  30. the posting, I've replaced a Carriage Return with "^M" and an ESC with "^["
  31. in ex's "map" command:
  32.  
  33. ----cut here and replace control characters---
  34. # Edit history list at line containing last command (open mode).
  35. # Get up to 22 most recent commands.
  36. # To work properly, put in .login:  alias r source /usr/local/bin/redo
  37. # Author unknown.
  38. history -h 22 >! /tmp/redo.$$
  39.  
  40. # Make CR map to :wq! and start ex quietly at 2nd to last line in open mode.
  41. ex - '+map ^M :.wq\!^[|set redraw|$-1 open' /tmp/redo.$$
  42.  
  43. # Insert into history without executing.
  44. source -h /tmp/redo.$$
  45.  
  46. # Clear out temporaries.
  47. /bin/rm -f /tmp/redo.$$
  48.  
  49. # If thing chosen to redo is the redo alias itself then DON'T redo it.
  50. if (!-2:0 != !!:0) !!
  51. ----cut here----
  52.  
  53. This works quite well with Sun's csh (which presumably is the original,
  54. given who wrote csh :-) but doesn't quite manage it with some imitiations,
  55. e.g. Interactive Unix V.3 . Even on the Sun it exposes a csh bug: if the
  56. redone command is an alias, csh will moan that it can't find the command.
  57. Doing a manual "!!" after that will work fine.
  58.  
  59. Method (2): using "vi" as a command shell:
  60.  
  61. My copy of vi will accept a map entry of the form:
  62.     :map #n ms"syy@s`s
  63. This will cause the current line to be read as a "vi" command: if that
  64. command is ":r! ...", then you'll read in a unix command. I have this as a
  65. permanent map entry!
  66.  
  67. Ian
  68. --- What *is* a .signature file?
  69.