*BSD News Article 41489


Return to BSD News archive

Xref: sserve comp.editors:12133 comp.unix.bsd:15965
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!ihnp4.ucsd.edu!agate!bostic
From: bostic@toe.CS.Berkeley.EDU (Keith Bostic)
Newsgroups: comp.editors,comp.unix.bsd
Subject: Re: Obscure (to me, at least) bug in vi
Date: 24 Jan 1995 17:46:26 GMT
Organization: University of California, Berkeley
Lines: 48
Distribution: inet
Message-ID: <3g3edi$8it@agate.berkeley.edu>
References: <3f79vk$5c@darkstar.UCSC.EDU> <3g25g9$avc@griffin.itc.gu.edu.au>
NNTP-Posting-Host: toe.cs.berkeley.edu

In article <3g25g9$avc@griffin.itc.gu.edu.au>,
Tony Nugent  <haynes@cats.ucsc.edu> wrote:
>
>haynes@cats.ucsc.edu (James H. Haynes) writes:
>
>I have a user who gets into those dark, cobwebby corners of vi.
>Here's a bug he reported to me.
>
>Make a .exrc file containing the line
>    map _ /-$(esc)JxX
>where (esc) is the escape character.
>
>Make a test file containing the likes of
>
>aaaa-
>aaaaa
>bbb-
>bbbbbb
>
>and edit it.  The thing in the .exrc file maps the underbar character to be
>an end-of-line-hyphen remover.  You'll see that it works.
>
>Now try   S    to substitute something for the whole line.  You'll find on
>some versions of vi that the characters in the macro get stuck into the
>line you are editing; specifically it will contain JxX-  before you type
>anything further.

What's going on is that vi has the following internal mappings:

        A  to  $a
        I  to  ^i

        C  to  c$
        S  to  c_
        Y  to  y_

A and I are safe; in the case of C, S, and Y, however, the
mappings are done by changing the current command character,
and pushing the operator ($, _ and _, respectively) onto the
queue of input keys.  While I haven't proven this, my belief
is that those keys are subjected to map expansion, resulting
in the behavior your user saw.

I also believe, but haven't proven, that you can get similar
behavior with the P/p commands, if the a/i keys are mapped.

Keith Bostic
bostic@cs.berkeley.edu