How to use vim macro to speed up your complex find/replace operations in vim / ideavim
Yesterday, I need to replace a string ClassName
with List<ClassName>
many times in a few files, and the ClassName varies. Manually doing it again and again is tedious and mistake prone, which is what I hate. Here's the solution
First, record a macro,
- move cursor on any letter of the target ClassName
- qa
- ysiw>
- Insert
- List
- Esc
- q
Second, replay the macro, move cursor to another occurrence of ClassName,
@a
Third, replay the same macro as many times as you want: move cursor to any other occurrences, simply type
@@
The feeling is so good to let a computer do what you want it to do!
and here's the Reference where I learnt how to use vim macro. TL;DR;