🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #2794

Re: Paste from macro in VI

#2794
From: Hans Mulder
Date: Wed, 12 Jun 1991 10:14
62 lines
2440 bytes
In <1096@dri500.dri.nl> slootman@dri.nl (Paul Slootman) writes:

>In article <1991Jun11.183544.514@otago.ac.nz> andrew@otago.ac.nz writes:
>>For a long time I have been trying to find a way around an anoying feature of
>>vi.  What I want to do is to create a macro (with :map) that will copy the
>>contents of this line onto the end of itself.

>>This can be done outside a macro with YPJ [...]

>Try:
>:map <macrosequence> :s/.*/&&/^V^M

>The ^V^M is a control-V followed by a return, to get the return into the
>mapping. Note: this does not do exactly the same as YPJ; *that* inserts
>a space between the original contents and the newly appended characters.
>To get the same effect with this mapping, add a space between the two
>ampersands ('&').

It's similar, but not still quite the same.  The major difference is that
YPJ deletes leading whitespace from the second copy while glueing, while
:s/.*/&& retains it.  A closer approximation would be

:s/[^ ^I].*/& &^V^M
     ^ that's caret+space+tab

There's still a minor difference, though:  YPJ inserts 2 spaces if the
line ends with a '.', but none if it begins with a ')'.

To get exactly the same behavior as YPJ, you could type

:map v :t-^V^V|j^V^M

(It takes two control-Vs to properly quote a '|', but only one to quote a ^M.)

In article <1991Jun11.113800.16672@umbc3.umbc.edu> rouben@math1.math.umbc.edu
(Rouben Rostamian) reports that 

:map v "aY"aPJ

more or less works under Ultrix.  The same is true for vi version SVR3.1, the
one that comes with SunOS 4.1 (and presumably with System V Release 3.1).

And then there is my proposal

:map q P
:map v YqJ

I still don't understand why that works, and straight

:map v YPJ

does not.  But then, I also don't understand why

:map q fq

produces a "No tail recursion" message when (1) it isn't tail recursive
and (2) vi handles recursive :maps just fine.

--
Happy hacking,

Hans Mulder	hansm@cs.kun.nl
Technical Details
Message-ID: <3641@wn1.sci.kun.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm
References: <1991Jun11.183544.514@otago.ac.nz> <1096@dri500.dri.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm
From: hansm@cs.kun.nl (Hans Mulder)
Newsgroups: comp.editors
Subject: Re: Paste from macro in VI
Message-ID: <3641@wn1.sci.kun.nl>
Date: 12 Jun 91 10:14:09 GMT
References: <1991Jun11.183544.514@otago.ac.nz> <1096@dri500.dri.nl>
Sender: root@sci.kun.nl
Organization: University of Nijmegen, The Netherlands
Lines: 62