Vim Macro Recording & Replay
Intermediatev1.0.0
Master Vim macro recording for batch text transformations — record, replay, edit, and chain macros to automate repetitive editing tasks across files.
Content
Overview
Vim macros record a sequence of keystrokes and replay them with a single command. They're the fastest way to apply repetitive edits across lines, paragraphs, or entire files — far faster than find-and-replace for complex transformations.
Why This Matters
- -Eliminate repetitive editing — record once, replay thousands of times
- -Handle complex transformations — macros capture any Vim operation
- -No regex needed — use normal editing commands in the macro
- -Composable — chain macros with counts and ranges
How It Works
Step 1: Record a Macro
Step 2: Replay the Macro
Step 3: Apply Across Ranges
Step 4: Edit a Recorded Macro
Practical Examples
Convert CSS to Tailwind Classes
Add Console.log for Debugging
Transform JSON Keys
Best Practices
- -Start macros at a consistent position — use
0or^at the start - -End with motion to next target —
jfor line-by-line,nfor search-based - -Use text objects in macros for resilience (
ciwvs fixed-length changes) - -Test on one line first before running on a range
- -Macros stop on error — use this as a natural termination condition
Common Mistakes
- -Forgetting to end recording with
q - -Not positioning cursor consistently at macro start
- -Using absolute positions instead of motions (column 15 vs
f") - -Recording mouse clicks (macros are keyboard-only)
- -Not testing the macro before applying to a large range
FAQ
Discussion
Loading comments...