Subject: Vi Macros: Repeating a Binding Several Times.

From: Shlomi Fish <[email-masked]>
Date: Fri, 22 Feb 2002 08:11:46 +0200 (IST)

Hi!

I created the following binding in a Vim file:

map <F3> 5gg"ny$gg$a[<C-R>n]<ESC>5gg<C-X>

What it does is append a string containing "[", the number that appears in
line 5, and a "]" to line 1, and then decrement the number in line 5 by 1.

I'd like write a macro that repeats this procecure 10 times. However,
writing 10<F3> in the command line does something else entirely, because
the 10 is joined with the 5 to have 105gg.

Now, in an interactive mode I can use the q-recording, but it is not
available in mappings.

What should I do?

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: Tzafrir Cohen <[email-masked]>
Date: Fri, 22 Feb 2002 09:06:50 +0200 (IST)

> Now, in an interactive mode I can use the q-recording, but it is not

Just in case vi doesn't have a viable solution for that (or just in case
you want to further complecate Adi's life) recall that vim (not vi) also
has functions.

-- 
Tzafrir Cohen
mailto:[email-masked]
http://www.technion.ac.il/~tzafrir

---

From: Shlomi Fish <[email-masked]>
Date: Fri, 22 Feb 2002 11:18:14 +0200 (IST)

> you want to further complecate Adi's life) recall that vim (not vi) also

I want to implement it without using the vim specific functions. Pure Vi
macros.

Regards,

	Shlomi Fish

> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

---

From: Shlomi Fish <[email-masked]>
Date: Fri, 22 Feb 2002 17:23:57 +0200 (IST)

I discovered that it is possible to place a string inside a macro (using
y) and then to execute it as if it was a sequence of commands. That solved
my problem, after some mapping trickery.

Regards,

	Shlomi Fish

---

From: Adi Stav <[email-masked]>
Date: Sat, 23 Feb 2002 12:40:17 +0200

> On Fri, 22 Feb 2002, Shlomi Fish wrote:
.
.
> > map <F3> 5gg"ny$gg$a[<C-R>n]<ESC>5gg<C-X>
.
.
> you want to further complecate Adi's life) recall that vim (not vi) also

My life is sufficiently complicated by the command itself :)

A few notes in case you want to make it intra-vi portable (using 
the '^' notation for special characters): 

5G is the traditional way to do exactly the same thing as 5gg . 
Less characters to type, too. Likewise, 1G is gg .

Traditional vi doesn't have that many commands in insert mode, 
so the portable way to do a[^Rn] is a[^["npa]^[ . 

^X is a vim-only command -- both nvi and vim support #- which 
does the same thing, and therefore is more portable (as well as
easier to remember IMHO). IRIX vi supports neither. If you want to 
be /that/ portable, you may have to jump through the following 
hoop: A-1^[!!bc^M . An incredibly useful command, this !. 
Note that it only pipes complete lines, though, which is one of 
the more annoying vi/ex limitations in my opinion, and the reason 
why I wrote !! instead of !$ . There might be more elegant ways to 
do the same thing using some ex abuse, but I can't think of any.

The last thing is that traditional vi macros (in IRIX, at least, 
nvi is fine with that) can't do yank/paste operations on 
incomplete lines, so you'd have to adjust the logic a bit. I 
admit it sucks.

So far I have: 

5G"nyy1G"npI[A]kJ5GA-1!!bc

which works even on my IRIX. Yay. INTERCAL never had a chance.