playback recording by range?

0 views
Skip to first unread message

Bee

unread,
Nov 24, 2009, 12:06:39 PM11/24/09
to vim_use
I can record keystrokes to a register
I can playback the register
I can playback the register count times
Is there a way to playback the register by range?

--
Bill
Santa Cruz, California

Tim Chase

unread,
Nov 24, 2009, 12:19:44 PM11/24/09
to vim...@googlegroups.com
> I can record keystrokes to a register
> I can playback the register
> I can playback the register count times
> Is there a way to playback the register by range?

Though untested, my first thought would be something like

:'<,'>g/^/norm @z

(assuming your macro was in register "z")

Which in theory could be extended to execute a macro on lines
matching a regexp:

:g/regexp/norm @z


If it doesn't work, I'm sure others out there have good
suggestions (that they've tested ;-) too.

-tim

Jürgen Krämer

unread,
Nov 24, 2009, 12:22:29 PM11/24/09
to vim...@googlegroups.com

Hi,

Tim Chase wrote:
>
>> I can record keystrokes to a register
>> I can playback the register
>> I can playback the register count times
>> Is there a way to playback the register by range?
>
> Though untested, my first thought would be something like
>
> :'<,'>g/^/norm @z
>
> (assuming your macro was in register "z")

no need to use :global,

:'<,'>normal @z

works, too.

> Which in theory could be extended to execute a macro on lines
> matching a regexp:
>
> :g/regexp/norm @z
>
>
> If it doesn't work, I'm sure others out there have good
> suggestions (that they've tested ;-) too.

Just tested. ;.)

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

Tim Chase

unread,
Nov 24, 2009, 12:44:14 PM11/24/09
to vim...@googlegroups.com
Jürgen Krämer wrote:
>> :'<,'>g/^/norm @z
>>
>> (assuming your macro was in register "z")
>
> no need to use :global,
>
> :'<,'>normal @z
>
> works, too.

I've had just enough trouble forgetting which Ex commands (mostly
the ones I don't use regularly) accept a range and which default
to the first or last line of that range. So I tend to toss in
the extra "g/^/" guard to make sure the operation is happening on
each line rather than guess wrong and have to undo+rerun the
command. ":exec" and ":put" are the big ones I guess that
regularly get me (or rather "got" me...before I started using the
:g form). ":norm" lumps in my head with ":exec", but on reading
the docs (and Jurgen's evidence) ":norm" takes a range, and
":exec" balks at it.

-tim

Reply all
Reply to author
Forward
0 new messages