Thursday, March 29, 2012

Re: executing a recording on a selected block

On Thursday, March 29, 2012 12:48:25 AM UTC-5, sinbad wrote:
> how to execute a recording on a selected visual block.
>
> -sinbad

I'm assuming you have a macro that does some work on a single line, and you want to apply it to every line in a visual selection. Assuming the macro is in the 'q' register, there are two good ways to do this:

1. Take your existing macro, and run it on every line in the selection, using :'<,'>normal! @q
2. Rather than operating on a visual selection:
a. count the number of lines you wish to run the command on. 'relativenumber' is a good option to help with this.
b. make your macro move to the next line when it is done; if you already have a macro which does work but doesn't move, you can add the movement to the end. Just type qQjq to append a 'j' command to the end of the q register.
c. execute the macro with a count equal to the number of lines to operate on. For example, to operate on 10 lines starting at the cursor, type 10@q

--
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:

Post a Comment