How do I run the last executed macro across an existing visual line range?
Answer
:'<,'>normal @@
Explanation
When you already have a useful macro but need to apply it to a specific block of lines, :'<,'>normal @@ is a high-leverage pattern. It replays the most recently executed macro over the current visual range, so you do not need to restate the register name or re-record anything. This is especially useful during structured cleanup where the target region changes but the macro logic stays the same.
How it works
'<,'>is the range captured from the last visual selection:normalexecutes normal-mode keystrokes on each line in the range@@replays the last executed macro register
The practical advantage is workflow speed: execute a macro once where it works, visually select a region, then apply the same behavior everywhere in that region with one Ex command.
Example
Suppose you already executed a macro that normalizes log prefixes on a single line. You then visually select a block of related lines and run:
:'<,'>normal @@
Vim applies the same macro to each selected line, preserving the exact sequence that just worked.
Before: mixed formatting across selected lines
After: consistent formatting using your last macro
Tips
- If mappings interfere, use
:normal!and call a specific register instead (@q). - Re-execute one line with
@@first to validate behavior before range-wide application.