Saturday, March 5, 2011

calling macros single time and multiple times - what's difference?

Hello!
There's macros: it uses value from register to perfom modifications
dependent on this value and then stores new value back into register.
It's like macro with a state. It makes its job when called once with
@<register> but it fails when called multiple times with
<number>@<register>. Why?

Here's vimgolf problem to make things clear.
One need change this:

line1
line2
...

to this:

1. line1
2. line1


I preform %s/^.*/1. &/g to make numbers. Every number is 1. Then i
move cursor to first 1 and record macro. Yank symbol into register s,
move to next line, prefom multiple increments (increment count is in
register s, @s<C-A>), then yank incremented value into register s.
This macro works when called single time and it doesn't work when
called multiple times. Why?

One can change multiple increments with just
pasting-incrementing-yanking incremented value. It doesn't matter.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: