[comp.editors] Can you write complex vi macros?

gregm@otc.otca.oz.au (Greg McFarlane) (03/14/91)

It seems that you cannot have more than one "undo-able" vi command in the
one macro. This means that a complex vi macro must be split into several
smaller macros.

I'll explain what I mean by an example. Edit a file and type ":map Q rXY".
This should map the Q key to "replace the character under the cursor with X
and yank the line". But when I type Q, vi tells me "Can't yank inside
global/macro" and goes into ex mode. However if I type ":map Q rXT" and
":map T Y", everything is OK. I get this behaviour on a Sparc 1+, a Sun 3/50
and a Pyramid.

Does this happen at your site? Is there a reason for this madness?

-- 

                   ACSnet:  gregm@otc.otca.oz.au
Greg McFarlane       UUCP:  {uunet,mcvax}!otc.otca.oz.au!gregm
|||| OTC ||         Snail:  OTC R&D GPO Box 7000, Sydney 2001, Australia
                    Phone:  +61 2 287 3139    Fax: +61 2 287 3299

torek@elf.ee.lbl.gov (Chris Torek) (03/18/91)

In article <2483@otc.otca.oz> gregm@otc.otca.oz.au (Greg McFarlane) writes:
>It seems that you cannot have more than one "undo-able" vi command in the
>one macro. This means that a complex vi macro must be split into several
>smaller macros. ... Is there a reason for this madness?

It has a lot to do with the `chipping to fit on a PDP-11' that I
mentioned a few articles back.  The innards of vi share this buffer
with that one, with horribly complex rules.  As a result you can
occasionally find a sequence that causes bizarre results.  It used to
be the case, for instance, that combining wrapmargin with abbreviations
(I think) could goof up the file you were editing.
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov

gast@maui.cs.ucla.edu (David Gast) (03/21/91)

In article <2483@otc.otca.oz> gregm@otc.otca.oz.au (Greg McFarlane) writes:
>It seems that you cannot have more than one "undo-able" vi command in the
>one macro. This means that a complex vi macro must be split into several
>smaller macros.

Not correct.  Consider:

  :map X rxlrx     (where is X can be another character)

This map changes the character under the cursor to x and then changes
the character to the right to x.

u will undo both changes.

As a general rule, your statement is not correct.

> vi tells me "Can't yank inside global/macro"

Vi has a known bug with respect to the unnamed buffer.

David Gast