Re-indenting with Notepad++ regex replace
08 Oct 2020
The other day I came up with a ridiculously inefficient regex replace for Notepad++ to re-indent some code from 3 spaces per indent (my team’s standard for a certain codebase – no idea how they settled on 3) to 1 (for tight display on this blog).
- Search -> Replace (ctrl+H)
- Search Mode: Regular expression
- Start with Find what of:
^ ([^ ])
- Start with Replace with of:
Repeat, adding 3 spaces at a time after the
^to Find what and 1 space at a time to the beginning of Replace with, until the following replace (and the one before it), at 6 & 7 levels deep of indenting, both had 0 results
Stopped at Find what of:
^ ([^ ])
- Stopped at Replace with of:
I’m sure I could have done better, but it got the job done.
What do you do to quickly change the indentation of code?<! -- I could get really fun here by including a 2nd link to prev/next if it's not in your language but it has an alt that is. --> <! -- Also, I need to CSS-style these to float left and right, like paginators. -->