-
Notifications
You must be signed in to change notification settings - Fork 0
Execute macro repeatedly until the end of a range is reached.
vim-scripts/RangeMacro
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a mirror of http://www.vim.org/scripts/script.php?script_id=3271 DESCRIPTION Macros are a fantastic way to apply the same modification many many times. Just record once and then repeat, repeat, repeat... Though it's easy to repeat (@@, [count]@{0-9a-z".=*}) a macro, explicit repeating becomes cumbersome when you're dealing with hundreds of repeats. You can write a recursive macro (i.e. invoking the macro at the end), but that will execute over the entire buffer, until the macro errors out on the border of the buffer. Simple macros that mostly restrict themselves to a single line can be repeated via :[range]normal @{0-9a-z".=*}, but that breaks when lines are inserted or removed, or the macro jumps to other lines. What's needed for extensive macro repetitions is to repeatedly execute the macro over a range, and stop once the macro navigates out of the range. This plugin provides a :RangeMacro command and mappings that execute a recorded macro over a range, area of text covered by {motion}, or the current seletion. RELATED WORKS - CommandWithMutableRange.vim (vimscript #3270) executes commands which may add or remove lines for each line in the range. USAGE :[range]RangeMacro {0-9a-z".*+} Position the cursor on the first column of the start of [range] and execute the contents of register {0-9a-z".*+} repeatedly until the cursor moves beyond the lines covered by [range]. <Leader>@{0-9a-z".*+}{motion} Repeatedly execute the contents of register {0-9a-z".*+} until the cursor moves outside the text covered by {motion}. {Visual}<Leader>@{0-9a-z".*+} Position the cursor on the first column of the selection and execute the contents of register {0-9a-z".*+} repeatedly until the cursor moves outside the selection. All selection modes are supported: characterwise, linewise and blockwise. Note: The check whether the macro moved outside the range is only done _after_ each macro invocation. During macro evaluation, jumps outside the range can be used and will not stop macro execution. SUITABLE MACROS To make a macro repeatable, the macro must move to the position where the next macro call needs to take place, typically either as the first or last command of the macro. The macro will always be executed from top to bottom of the range, regardless of how {motion} or the selection was made. So, for example, if the macro processes line(s) sequentially, append the "j" command to move to the next line; if the buffer areas are located via searching, you could use the "n" command to move to the next match.
About
Execute macro repeatedly until the end of a range is reached.
Resources
Stars
Watchers
Forks
Packages 0
No packages published