[comp.editors] vi command does not work in macro

dolf@idca.tds.PHILIPS.nl (Dolf Grunbauer) (10/13/89)

I wanted to duplicate a word somewhere in the middle of a sentence.
The command I used was:
        df Pp
(There is a space between the 'f' and 'P')
After having noticed I required a lot of these duplications, I defined:
        :map v df Pp
Invoking the macro `v' did not do the job: the word is only preceeded by
a `p', leaving the cursor at the space after the involved word.
Apparently the word is deleted (by the `df '), put back (by the `P')
and the `p' is inserted in the front. This really puzzles me. Why is p
inserted (there is no `aAiI') and why in the front (at the back seems a
more logical place as that is where the cursor is) ?
-- 
Dolf Grunbauer          Tel: +31 55 432764  Internet dolf@idca.tds.philips.nl
Philips Telecommunication and Data Systems  UUCP ....!mcvax!philapd!dolf
Dept. SSP, P.O. Box 245, 7300 AE Apeldoorn, The Netherlands

rostamia@umbc5.umbc.edu (Rouben Rostamian) (10/15/89)

In article <273@ssp1.idca.tds.philips.nl> dolf@idca.tds.PHILIPS.nl (Dolf Grunbauer) writes:
>
>I wanted to duplicate a word somewhere in the middle of a sentence.
>The command I used was:
>        df Pp
>(There is a space between the 'f' and 'P')
>After having noticed I required a lot of these duplications, I defined:
>        :map v df Pp
>Invoking the macro `v' did not do the job: the word is only preceeded by
>a `p', leaving the cursor at the space after the involved word.
>Apparently the word is deleted (by the `df '), put back (by the `P')
>and the `p' is inserted in the front. This really puzzles me. Why is p
>inserted (there is no `aAiI') and why in the front (at the back seems a
>more logical place as that is where the cursor is) ?

The vi macros apparently do not handle yank and put of partial lines very
well.  You would run into the same problem if you defined a macro to yank and
put a partial line into a named buffer (as in "xy$"xp or in "xy`m"xp).
However, full lines are handled correctly (as in "xyy"xp or in "xy'm"xp).  I
do not know if this is a peculiarity of vi in Ultrix -- I am running Ultrix
on a DECstation3100 -- or if it is an inherent bug in vi.


Rouben Rostamian                               Phone: 301 455-2458
Department of Mathematics                      e-mail:
University of Maryland Baltimore Counnty       rostamian@umbc.bitnet
Baltimore, MD 21228                            rostamian@umbc3.umbc.edu

steinbac@hpl-opus.HP.COM (Gunter Steinbach) (10/18/89)

    This must be a bug in your implementation.  

    As a macro or otherwise, 'df Pp' works fine for me in HP-UX 6.2 on an
    HP9000/350 workstation.  I dimly remember related problems, though, some
    years and OS versions ago.

    No plug for HP intended.

	     Guenter Steinbach	 |	 hplabs!gunter_steinbach
				 |	 gunter_steinbach@hplabs.hp.com

kevin@ttidca.TTI.COM (Kevin Carothers) (10/19/89)

In article <62420007@hpl-opus.HP.COM> steinbac@hpl-opus.HP.COM (Gunter Steinbach) writes:
>
>    This must be a bug in your implementation.  
>
>    As a macro or otherwise, 'df Pp' works fine for me in HP-UX 6.2 on an
>    HP9000/350 workstation.  I dimly remember related problems, though, some
>    years and OS versions ago.

 Mine works too. This doesn't, tho:

 :map ^A ddjjjp       (A)

Obviously, I'm simply moving the  current line down  3 lines.
This gives the message "Cannot put inside global/macro".
But this DOES work:

 :map ^A 0d$P          

I am NO VI internals expert, but the most obvious  reasoning  is 
that VI can't scroll the screen from inside a macro. Armed with this
basic (maybe erroneous) assumption, I can get something like "(A)" 
above to work by the following:

 :map ^A ma3jo^[mb'ad$'bp        [...Aren't macros fun? :)]
         ^      ^
         -------------> Please, I know these are unnecessary in this 
                        example
                        
NOW - My questions:
 1. This works file on single lines, but simply terribly on entire
    paragraphs.  Does anyone have macros  (hopefully straightforward ones)
    to move Multiple lines/blocks from within a macro?   

 2. Does anyone have any ideas on ways to pass parameters to macros? Is there
    a version of VI that does?

--
    Kevin Carothers           {philabs,csun,psivax}!ttidca!kevin

maart@cs.vu.nl (Maarten Litmaath) (10/21/89)

kevin@ttidca.TTI.COM (Kevin Carothers) writes:
\...
\ :map ^A ddjjjp       (A)

	:map ^A :m+2^V^M

Especially for macros `ex' commands are worth learning too.

\... "Cannot put inside global/macro".

Vi's implementation is sick.

\ 1. This works file on single lines, but simply terribly on entire
\    paragraphs.  Does anyone have macros  (hopefully straightforward ones)
\    to move Multiple lines/blocks from within a macro?   

Something along the lines of this:

	:map v {jma}kmb:'a,'bm'c^V^M

This will put the current paragraph (without surrounding empty lines) below
the line marked `c'.

\ 2. Does anyone have any ideas on ways to pass parameters to macros? Is there
\    a version of VI that does?

You could let the user enter the parameters on a new line, and delete this
line into a register, to be executed with the `@<a-z>' command.
-- 
A symbolic link is a POINTER to a file, | Maarten Litmaath @ VU Amsterdam:
 a hard link is the file system's GOTO. | maart@cs.vu.nl, mcsun!botter!maart

allbery@NCoast.ORG (Brandon S. Allbery) (10/24/89)

As quoted from <7036@ttidca.TTI.COM> by kevin@ttidca.TTI.COM (Kevin Carothers):
+---------------
| NOW - My questions:
|  1. This works file on single lines, but simply terribly on entire
|     paragraphs.  Does anyone have macros  (hopefully straightforward ones)
|     to move Multiple lines/blocks from within a macro?   
+---------------

Have you considered using :t ?  Remember, you have all of "ex" available for
use as well as most of "vi".

+---------------
|  2. Does anyone have any ideas on ways to pass parameters to macros? Is there
|     a version of VI that does?
+---------------

I don't think so.

++Brandon
-- 
Brandon S. Allbery, moderator of comp.sources.misc	     allbery@NCoast.ORG
uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu bsa@telotech.uucp
161-7070 (MCI), ALLBERY (Delphi), B.ALLBERY (GEnie), comp-sources-misc@backbone
[comp.sources.misc-related mail should go ONLY to comp-sources-misc@<backbone>]
*Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*