[comp.editors] Another bug in vi ?

wd@samsa.pcs.com (wd) (10/02/90)

If I define

	:map! #a foo

and type "#a" while in insert mode, my version of vi appends some
garbage after inserting "foo"  (usually it looks like "fooa", but
I have seen "fooli" and other garbage, too). This happens only if
the first character of the mapped pattern is a '#'.   It does not
depend on the rest of the pattern.

*  My vi reports "Version SVR3.1" on ":ve". Do other versions of
   vi have the same bug?

*  Is there an easy work around to get "#a" working?

*  Has anybody a solution for this problem (a bug fix)?


- Wolfgang

==================================================================
Name    : Wolfgang Denk
Company : PCS GmbH, Pfaelzer-Wald-Str. 36, 8000 Munich W-Germany.
UUCP    : ..[pyramid ;uunet!unido]!pcsbst!wd  (PYRAMID PREFERRED!!)
DOMAIN  : wd@pcsbst.pcs.[ COM From rest of world; DE From Europe ]
######## The purpose of computing is insight, not numbers! ########

smk@cbnews.att.com (Stephen M. Kennedy) (10/03/90)

In article <896@pcsbst.pcs.com>, wd@samsa.pcs.com (wd) writes:
> If I define
> 
> 	:map! #a foo
> 
> and type "#a" while in insert mode, my version of vi appends some
> garbage after inserting "foo"  (usually it looks like "fooa", but
> I have seen "fooli" and other garbage, too). This happens only if
> the first character of the mapped pattern is a '#'.   It does not
> depend on the rest of the pattern.

Believe it or not, this is a vi (mis?)feature.  A lhs of '#a' means
function key 'a' to vi.  Yes, even though you probably don't have a
function key 'a'; a more common usage is '#1' for function key 1, etc.  In
insert/replace/append mode, vi seems to expect function keys to map to a rhs
that does an <ESC> to go into command mode and then does cursor positioning
commands.  Vi then endeavors to put you back into insert/replace/append mode
at the right spot with the appropriate 'a', 'i', 'li', etc. commands.  Your
"function key" definition doesn't follow this <ahem> undocumented protocol,
so you get the trailing 'a' or 'li' garbage because you never left
insert mode in the first place.  Vi predefines mappings for the up, down,
left, right, and home function keys for most terminals.  I'm not sure I 
see the utility of this kind of cursor positioning within i/r/a mode;
perhaps for editing a table in replace mode?

Workarounds?

	- Don't use # as the first character of the lhs.
	- End rhs with <ESC> (gak) (I didn't try this either)

Steve Kennedy
smk@cbosgd.att.com

> Company : PCS GmbH, Pfaelzer-Wald-Str. 36, 8000 Munich W-Germany.
Congratulations!  I hope it works out for you.

ray@vantage.UUCP (Ray Liere) (10/05/90)

I tried your test on our vi and it did not do anything unexpected. We are using
a relatively old version of vi -- :ve reports
		HP Version  @(#) $Revision: 32.9 $
which is probably not very informative -- it's executable is dated Jun 1 1987,
I believe it is system 5.2 ... hope this helps.

Ray Liere
Vantage Consulting and Research Corporation
voice: (503)657-7294
uucp: uunet!nwnexus.WA.COM!vantage!ray
       -or-
      uunet!nwnexus!vantage!ray
       -or-
      hplabs!hpubvwa!hpupora!vantage!ray
Internet: ray%vantage@nwnexus.WA.COM

gast@lanai.cs.ucla.edu (David Gast) (10/07/90)

In article <1990Oct3.150431.19010@cbnews.att.com> smk@cbnews.att.com (Stephen M. Kennedy) writes:
>In article <896@pcsbst.pcs.com>, wd@samsa.pcs.com (wd) writes:
 
>> 	:map! #a foo
>> and type "#a" while in insert mode, my version of vi appends some
>> garbage after inserting "foo" 

>Believe it or not, this is a vi (mis?)feature.  A lhs of '#a' means
>function key 'a' to vi.

Under SunOs 4.0, there is not a problem.  Perhaps the error is related
to Sys V.

David Gast
gast@cs.ucla.edu
{uunet,ucbvax,rutgers}!{ucla-cs,cs.ucla.edu}!gast