Download Align Assignments on the VS Gallery, and check out the source on github.
About a month ago, a blog article about "TextMate shortcuts you should be using" came across my feed reader. The third item down on that list is "Align Assignments", which lines up successive equals signs (=) in a block of text. This wasn't the first time I've heard of complaints about this feature being missing from VS, oftentimes from SlickEdit users. In that product, it is called "Align on equal" and happens automatically, but the principle is similar.
=
The idea is to take this:
...and turn it into this:
I figured that this would also make an interesting extension, because it requires a new command to be registered, and thus you have to have an extension that is both a package and MEF component. Since I had such a hard time of it last time around, I was hoping to do it "the right way" this time around, meaning to start with a package and turn it into a MEF component.
The logic I used for this was pretty straightforward, found in CommandFilter.cs. The algorithm is essentially:
(2) is a bit clearer in code, I think. The overall logic is the AlignAssignments method, and the logic for calculating column/buffer offset is in the GetColumnNumberOfFirstEquals method.
There's also some magic about combining characters, to make sure it doesn't count a high/low surrogate pair as two columns.
The end result is a command that does basically what you want 95% of the time by just sticking the caret in the middle of a bunch of declarations (or after you've finished typing the last one and before hitting enter) and hit the shortcut without thinking too hard about it.
There is a caveat, at least for C# users. C# still tries to format these declarations back to single spaces between each element, so it'll undo the command the next time you insert an end brace, format the document, etc. To get around this, make sure the following option is toggled:
Tools->Options->Text Editor->C#->Formatting->Spacing->"Ignore spaces in declaration statements"
VB and C++ don't appear to have settings to control this, and they may just overwrite the alignment (I didn't check this). Not much this extension can do about that, unfortunately.
The more difficult part was the part around creating a command.
To this end, I spent about an hour reading random blog articles that I could find about .vsct files. Even after that, I still don't feel like I really understand what's going on. I started with a package this time (as I should have last time), with the Menu Command it generates, but it still took me over an hour to get the command to do what I want.
In any event, I ended up with a command that is bound to Ctrl+Alt+] (to match TextMate's Cmd+Opt+]) and placed somewhere in the Edit menu.
Ctrl+Alt+]
Cmd+Opt+]
The end result isn't especially complicated, though I doubt it is truly minimal for the behavior I want.
Here are some overall thoughts about .vsct files, for the curious:
Edit->Advanced
...especially if you are a TextMate or Visual SlickEdit user. This extension likely won't work exactly like TextMate, as I didn't compare it directly, and it isn't automatic like SlickEdit, but it can hopefully add at least some of the value of those features.