It has been a long time since I created a TIL entry here, but yesterday I wanted to move some PHP doc properties types to the proper property type that we already have for a while in PHP 7.4.
I tried to find a PHPStorm plugin for that, but couldn't, so I thought, macros in VIM is something that I've seen the power watching some twitch developers programming, but I never did it.
I got really happy with how easy it is to set up and run the macros, so here we go:
q this will start the macro recording
Give a name to it, for example
m it only accepts one character
Make all the movements that you want to record and reproduce in the future.
In my example above, for typed properties in PHP from the PHP Docblock, I put the cursor in the beginning of the line of the one line docblock and
wwwwvwhyjhhpkddjj0. This will pick the type from the docblock, add it after the property visibility but before the property and goes to the next line of docblock.
With that, you got yourself a recorded macro.
To run, type
@m, if you want to do it multiple times (5 for example), type
5@m, this will run the macro 5 times.