Technology blog written by a Microsoft C# MVP

Posts Tagged Macro

In all of my editors I have used, I have always written a macro to align equal signs in code. For me code has to be aesthetically pleasing and this process helps that by making the equal signs as well as other items line up.

The macro purpose is to align target text on the current and following lines looking for the text until it can no longer find it. At that point it stops, calculates which point is the farthest out and then moves all the other lines to that location.

There are actually two macros, one to only align just = signs and the other which asks for target text to align.

Before

Any Ask

There are actually two macros in this package for extra flexibility. Besides just aligning equal signs…the other macro will align anything. To do that it will prompt the user as to what to align. That can be either one character or a word or phrase.

After

Notes

Macro starts at current text editing position.

Tabs in document may interfer with calculation. If that is the case remove tabs or make sure they are evenly placed for all lines in question.

There are two public macros in this package (Align and AlignIt). Its best to assign them to similar keystrokes like Alt-F10 and Ctrl-Shift-F10.

This is a non-destructive macro, it will not delete lines or move items to other lines.

Once it cannot find the target text it will stop.

Download is in the form of a zip file which contains the vb code and a readme. There should not be viruses…but it is always good to check.