Rylogic Text AlignerThis version is for Visual Studio 2019 and earlier. For Visual Studio 2022 and above use this version Rylogic.TextAligner for Visual Studio 2022 Rylogic Text Aligner is now also available for Visual Studio Code! OverviewRylogic Text Aligner is an extension that adds two commands to the edit menu for vertically aligning text: Align and Unalign. Vertical text alignment is a powerful productivity aid when used in combination with column selection. Vertically aligned text also leverages your subconscious ability to spot patterns, making pattern-breaking bugs much easier to spot. Notice how much easier it is to spot the bug in the second of the following two code examples:
The Align and Unalign commands are available under the Edit -> Advanced Menu. For convenience however, I recommend creating keyboard shortcuts. Select Options from the Tools menu, and then Keyboard under the Environment section. Type "Edit.Align" into the search text field, then choose your keyboard shortcut, and click assign. Repeat the process for "Edit.Unalign". I prefer the shortcuts:
but the choice is up to you. Rylogic Text Aligner is highly configurable. After reading though these simple examples, check out the configuration options. Align CommandThe first, and most basic use case, is to align assignments:
To align some text, move the caret onto a line of text within a block and hit your keyboard shortcut. The extension intelligently searches above and below the current caret position, identifies the alignment group nearest the caret and aligns the text. Note that alignment is not limited to just assignments, repeatedly pressing your keyboard shortcut will identify other alignment groups and align to those. To demonstrate this, create a new text file and copy in the following text:
Now, move the caret to the position just after the 'r' in 'cucumber' and press your keyboard shortcut twice. The text should be aligned as follows:
You can also tell the extension to align to specific characters by selecting the text to align to before pressing your keyboard shortcut. For example, select a ';' character then align:
Sometimes there is a need to limit the range of lines that aligning is applied to. This can be achieved by selecting multiple lines before hitting align:
Notice that whole lines do not need to be selected. Unalign CommandThe Unalign command uses logic similar to Align to select the appropriate alignment group and range of lines to operate on. Unalign removes consecutive whitespace to the left of the matched pattern on each line. For alignment groups with leading space, a single whitespace character is added. Trailing whitespace is also removed for affected lines. Using the text example from above, unaligning should result in the following sequence. Notice that the priority of alignment groups is reversed, compared to Align, so that Unalign is almost the inverse operation:
Similarly, selecting text to unalign on is also possible:
The range that unaligning is applied to can be limited by multi-line selection. As before, whole lines do not need to be selected:
Unlike Align, the Unalign command can also be used with selected text where no alignment patterns match. In this case, the Unalign command replaces any consecutive white-space with single white-space characters. The command preserves leading indentation, and is aware of C-style literal strings, including multi-line strings so long as they are spanned by the selection.
Notice that multiple whitespace within the quoted literal string is preserved. ConfigurationThe character sequences recognised as 'alignable' are defined in the options. Select Options from the Tools menu, then Align Options under the Rylogic section. All options are saved to an XML file in your AppData folder:
Tabs vs. SpacesThe Alignment Characters option is used to select between different whitespace styles. The supported schemes are:
Alignment Groups and PatternsThe top panel lists the Alignment Groups, and the lower panel contains the Alignment Patterns for the selected group. The order of groups influences the priority when selecting a group for aligning. The patterns within each group are all considered equivalent. For example, in the image above, the 'Assignments' group is the highest priority and consists of three patterns that are all considered assignments; Each Alignment Group has a Leading Space value that is the minimum number of whitespace columns before any aligned text. In the example above, there is one column space between the end of 'assignments' and the '&&=' text. Each Alignment Pattern has an Offset and a Minimum Width. The offset controls the horizontal alignment of patterns within the Alignment Group. The matched text for each pattern is padded with whitespace, up to the pattern's minimum width. To edit and test a pattern, select the pencil icon to display the pattern editor: Ignore Line PatternThe ignore line pattern can be used to make certain lines invisible to the aligning algorithm. This can be useful for aligning definitions that are separated by blank lines and comments. For example, if the Ignore Line Pattern is set to the regular expression pattern More Example Alignment Patterns
Support & DonateIf you like Rylogic Text Aligner and would like to say thanks, a donation would be greatly appreciated. Bugs should be reported to support@rylogic.co.nz Version History
|