Yet Another Inappropriate Use of Macros
Tim Chase posted a clever little :substitute
command on Twitter:
Had some regex with lots of repeated \d in them like \d\d\d\d
— Tim Chase (@gumnos) May 18, 2023
Converted them all to \d{n} notation in vim using
:%s!\%(\\d\)\{2,}!\='\d{'.(strlen(submatch(0))/2).'}'!g
Just in case it's useful for anybody else.
As always, my instinct was immediately to see if you can do it as a macro1.
You can. Here’s how:
qqqqq/\v(\\d)+\zs\\dEnterc2l{2}Esc@qq@qqq/\\d{\d}{2}EnterCtrl-All3x@qq@q