VI(1) vs. the world

Chris Torek chris at umcp-cs.UUCP
Thu Oct 9 22:25:00 AEST 1986


>In article <113 at twg-ap.UUCP> narayan at twg-ap.UUCP (Narayan Mohanram) writes:
>>How about :g/old-string/s//new-string/gc for conditional replace. Or is
>>query replace something different.

I was ecstatic when I discovered a `confirm' (or `conditional')
suffix to substitute operations in vi.  (This was before I ever
saw Emacs.) Then I found that its implementation was rather flawed.
Vi performs the conditional replace by:

	1.  Printing the line.
	2.  Printing `^'s below the matched text.
	3.  Awaiting confirmation: y<RETURN> or n<RETURN> (others
	    presumably equivalent to `no').

1. and 2. are ugly---but that is not too bad.  3. sounds fine:
type `y' or `n'; if you hit the wrong key, use your back-space key
to correct it.  Naturally, I soon hit the wrong key.  I typed
control-H (my backspace; I dislike DEL).  Vi echoed ^, H.

You *cannot* correct a wrong answer here.  Why bother waiting for
RETURN then?  It would be better, I think, not to wait for RETURN,
and to accept only `y', `n', and `q' (quit), and perhaps uppercase
versions of these.

In article <847 at cuuxb.UUCP> mwm at cuuxb.UUCP (Marc W. Mengel) writes:
>Not to mention the ":map" and ":map!" commands for keyboard macro's.

Maps are tricky.  You can do a number of things with maps, but not
as much as in Emacs.  They do often suffice.

>And one volley for the other side: I really like to be able to say
>"15j" to go down 15 lines, and "40a -<ESC>" to be able to make an
>80 column dashed line.  Does Emacs, (or any other editor, for that
>matter) provide this repeat n times facility? (this is not a
>rhetorical question, I don't know...)

Yes, `but'.  To go down 15 lines, type meta-15 (type 15 while holding
down the meta key), or ESC 1 5, or control-U 1 5, then control-N.
Making a dashed line is more difficult.  Vi has a major advantage
over Emacs here.

In Emacs, you must announce in advance that you intend to repeat
something, do the operation, then say it is done; you can then
repeat that operation.  (This is much like constructing a map,
except that you can see what you are doing.)  The problem here is
that Emacs repeats only single operations.  A single operation can,
of course, be a `repeat the remembered operations' operation.

Vi too repeats only single operations, but vi has a much better
indicator as to what constitutes one operation.  One operation is
everything done from one trip in the `get command' loop to the
next.  If I type i, f, o, o, SPACE, ESC, vi knows that the last
operation was to insert `foo '.  Because Emacs is modeless, it does
not have this kind of clue.  Vi can then repeat the `insert the
word foo' operation, either with a repeat count given in advance
(`10ifoo<SP><ESC>') or with a `repeat last command' command
(`.........', or `9.').

Emacs's repeat is actually more powerful; it repeats *anything*.
There are things you cannot do in vi maps (`put's, e.g., are
restricted).  But vi's repeat is more convenient, and probably gets
used more often.

>P.S. A Challenge to those Other Editor users, I can write a vi macro to 
>	reverse the words on a line... can you?

I just type meta-control-T in my Emacs.

I know rather more than I might wish about both vi and Gosling
Emacs.  The innards of the latter are considerably cleaner.  I
believe there are fewer bugs in my (local version of) Emacs than
in my (4.3BSD-beta version of) vi.  But I use both editors regularly.
I pick the one that seems appropriate for the job.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix.wizards mailing list