[comp.editors] Paste from macro in VI

rouben@math13.math.umbc.edu (Rouben Rostamian) (06/11/91)

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  Withing a macro, I get the message
>"Cannot put inside global/macro".  I'm runnin on a SUN3/60 with SUNOS that
>announces itself as "Sun UNX 4.2 Release 3.5" and the version of vi that comes
>with it.

On ultrix you can get around this problem by yanking into a named buffer,
as in:
	"aY"aPJ
which will do what you want, but not perfectly.  For one thing, the terminal
beeps each time you execute the macro--I do not know why.  For another thing,
you may expect that after executing the macro, the buffer "a to contain the
previously yanked string, but it doesn't.  The bufer remains empty.

--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian@umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben@math9.math.umbc.edu

dattier@vpnet.chi.il.us (David W. Tamkin) (06/11/91)

andrew@otago.ac.nz wrote in <1991Jun11.183544.514@otago.ac.nz>:

| 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  Withing a macro, I get the message
| "Cannot put inside global/macro".  I'm runnin on a SUN3/60 with SUNOS that
| announces itself as "Sun UNX 4.2 Release 3.5" and the version of vi that comes
| with it.

It's a cheap workaround, but map a key to :s/.*/&&/^M (you'll need to type
ctrl-V ctrl-M, of course, to save it in a mapping).  Actually, YPJ puts a
space between the two appearances, so maybe you want :s/.*/& &/^M instead.

David Tamkin  PO Box 7002  Des Plaines IL  60018-7002  dattier@vpnet.chi.il.us
GEnie:D.W.TAMKIN  CIS:73720,1570  MCIMail:426-1818  708 518 6769  312 693 0591

"Parker Lewis Can't Lose" mailing list:
 flamingo-request@esd.sgi.com (reflector)    flamingo-request@mcs.com (digest)

hansm@cs.kun.nl (Hans Mulder) (06/12/91)

In <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  Withing a macro, I get the message
>"Cannot put inside global/macro".  I'm runnin on a SUN3/60 with SUNOS that
>announces itself as "Sun UNX 4.2 Release 3.5" and the version of vi that comes
>with it.

I'm running SunOS 4.1.1, which comes with a somewhat different version of vi,
but I believe that this trick is universal: hide the fact that you are yanking
and putting inside the same macro by throwing more macro's at it, e.g.

:map K P
:map g YKJ

works for me.

--
Have a nice day,

Hans Mulder	hansm@cs.kun.nl

andrew@otago.ac.nz (06/12/91)

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  Withing a macro, I get the message
"Cannot put inside global/macro".  I'm runnin on a SUN3/60 with SUNOS that
announces itself as "Sun UNX 4.2 Release 3.5" and the version of vi that comes
with it.

Andrew.

andrew@otago.ac.nz

slootman@dri.nl (Paul Slootman) (06/12/91)

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 ('&').
-- 
 ----------------
:slootman@dri.nl : When you get to the point where you think that nothing
:+ 31 5496 88831 : is impossible, try pushing toothpaste back into a tube
 ----------------

hansm@cs.kun.nl (Hans Mulder) (06/12/91)

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

stead@beno.CSS.GOV (Richard Stead) (06/15/91)

In article <1991Jun11.183544.514@otago.ac.nz>, andrew@otago.ac.nz writes:
> 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  Withing a macro, I get the message

The many other responses seem to be doing it the hard way.  vi doesn't like
the number of new lines to change during macros (at least that's what seems
to make it complain).  I never get complaints with something like:

:map q 0d$p0Pa ^[

This duplicates YPJ with no error reports, beeping, etc.  I am constantly
using macros with dwP<move>p commands in them to duplicate portions of lines
within lines.
--
Richard Stead
Center for Seismic Studies
Arlington, VA
stead@seismo.css.gov

jpr@jpradley.jpr.com (Jean-Pierre Radley) (06/25/91)

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.

map v :s/\(.*\)/\1\1/^M

where the ^M is inserted by first typing the ^V escape.


Jean-Pierre Radley   Unix in NYC   jpr@jpr.com   jpradley!jpr   CIS: 72160,1341