Code alignment


Code alignment helps you present your code beautifully, enhancing clarity and readability.

(64) Review
Visual Studio
2015, 2013, 2012, 2010
Download (130,156)
E-mail Twitter Digg Facebook
Add to favorites
Reviews (64)
Q and A (31)
Sign in to write a review
Sort by:

by Rodrigo Stuchi | September 30 2015

Great tool, use also in notepad++.

by yavital | July 06 2015

Chris. well done, works as I expected. Thanks. Worth mentioning the align by space and where to place cursor when aligning by space is used.

by Ken Cenerelli | June 13 2015

by Aditya Wardhana | February 26 2015

by Ryan Knuth | February 13 2015

So good! I have it for both VS and NotePad++. Will definitely donate :)

by RJM123 | February 03 2015

by casterle | January 27 2015

I've been using codealignment for some time now; hard to believe that I hadn't reviewed it until now.

Excellent product! If everyone used it, code maintenance would be much easier.

by JoseMigu3l | November 18 2014


by Seth Morris | October 19 2014

cpmcgrath October 19 2014
| Edit |

Thanks for the rating! Much Appreciated

by flybentley | September 08 2014

Poor alignment capability.
For example, when you align by ',' character you would expect it to align by all ',' characters.
In fact it just aligns by the first character.

cpmcgrath September 21 2014
| Edit |

Sorry about the delay responding. The fact is sometimes you want to align all commas and sometimes you only want to align one. In my experience one is more common.

To align multiple ones you can use the "Align from caret" option -

In version 10 I've also introduced "Alignment Chaining". I'll write something up about it soon, but basically if you have align by comma assigned to ctrl = press ctrl = keep holding ctrl and tap , a few times. This gives you complete control, and is super fast. If there's a colon you want to align by in the middle of the commas, then you can tap ,,;,,

by 3.1415926535 | July 20 2014

Thanks for this great tool!
This is going to save soooo much time.
I have been doing this manually for the last 100 years (OK it feels like that long).
Most other developers I have worked with could see value in formatting the code, but are far too lazy to do it manually.
This should be a standard part of VS so that all of the new programmers just use it as the standard, rather than the current "pretty awful print" that should be called code mangler!
Now no reason to accept poor quality code formatting at your next code review!

by Jeff Robison | May 31 2014

by Piotr Kula | April 15 2014

SO many years of pressing space bar to align code are over! Sometimes you just need this tool for mapping properties left and right for database saves. and the equals or space align is proper job!! Thanks man!

by AD_VS | April 01 2014

Brother, You are a Hero!

by David Jang in Korea | February 25 2014

Nice Job, nice tool.
For the first time, I'm writing down review here.
To write down here, I've just signed up here.
Hope to have a nice developing life :)

by Jes.Inc | December 11 2013

Please add align by tabs

cpmcgrath December 12 2013
| Edit |

Hi Jes, Here's an explanation of Tabs in Code Alignment -

by Fabio Armani | December 05 2013

Great. I can no longer do without it.

by SouthendRonnie | December 04 2013

by SegaWang | November 26 2013

Really perfect! My love tool~

by W.D. Stevens | October 22 2013

Excellent!!! Exactly what I've been doing manually for ages. Awesome!

cpmcgrath October 29 2013
| Edit |

Glad to hear! Thanks for the review!

1 - 20 of 64 Items   
Sign in to start a discussion

  • VS Autoformatting
    3 Posts | Last post September 28, 2015
    • I just discovered your extension and am loving it, however, I find myself fighting with Visual Studio's autoformatting feature.  Is there a way to prevent visual studio  destroying all my formatting whitespace?
    • Hi,
      Are you using C# or VB?
      In C# it's pretty easy. First, whenever Visual Studio formats, you can press ctrl z to undo.
      However, you can turn the formatting off in Options, go to "Text Editor > C# > Formatting > General"
      I untick all these options.
      VB's a bit harder, It's really aggressive with its autoformat. And the option to turn it off moves depending on your version of Visual Studio!
      In Visual Studio 2013 and below, it's in 
      "Text Editor > Basic > VB Specific" and the option to untick is "Pretty listing (reformatting) of code"
      In Visual Studio 2015, the option is in  
      "Text Editor > Basic > Advanced" and the option to untick is "Pretty listing (reformatting) of code"
    • I've just found out that in Visual Studio 2015 they decided to add some additional c# triggers for auto-formatting but not give us an option to turn it off.
      From what I have seen, in certain circumstances colon and open curly brace now causes an autoformat.
      Best thing we can do is send in frowns about it.
  • Wont install on 2015
    2 Posts | Last post August 06, 2015
    • 8/6/2015 6:20:03 AM - Searching for applicable products...
      8/6/2015 6:20:03 AM - Found installed product - Microsoft Visual Studio Express 2015 for Web
      8/6/2015 6:20:03 AM - Found installed product - Global Location
      8/6/2015 6:20:03 AM - Found installed product - ssms
      8/6/2015 6:20:03 AM - VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products.
         at VSIXInstaller.App.InitializeInstall(Boolean isRepairSupported)
         at VSIXInstaller.App.InitializeInstall()
         at System.Threading.Tasks.Task.InnerInvoke()
         at System.Threading.Tasks.Task.Execute()
    • Hi,
      From the look of the error you're trying to install it on Visual Studio Express. Visual Studio Express does not support extensions.
      I recommend trying Visual Studio 2015 Community - It's much more feature packed but does have a few stricter licencing conditions.
  • Alignment options
    8 Posts | Last post February 23, 2015
    • Given the following code, I'd like to place my cursor between the two open curly braces on the first line and have the following lines align on the 2nd curly brace.
      var a = { {one,three,five,b}, 
      var a = { {one,three,five,b}, 
                {seven,nine,five,eight },
      I've assigned a key to the regex: (\{|\[|\() with 'align by caret' checked. This works well in most circumstances. but in this case it doesn't work. I believe this is because you capture the caret column and then start from that point for subsequent lines. If this is the case, an option to start from the beginning of subsequent lines would solve my problem.
      If I had an option to add a space after the aligned character (in addition to the current option to insert a space before the aligned character), I could get the following which would be even better.
      var a = { { one,three,five,b}, 
                { seven,nine,five,eight},
                { ab,b,cc,z}};
      Then, using align by comma and a regex for the closing curly brace, I could get this:
      var a = { { one,   three, five, b     }, 
                { seven, nine,  five, eight },
                { ab,    b,     cc,   z     } };
      If there's not a better way to accomplish this, is it something you'd consider adding to your 'todo' list?
    • Hi,
      Sorry about the long delay on this. I somehow managed to miss it. It's a hard one to decide if a change should be made for. I'd normally just use column marking to move the subsequent lines across.
      Alternatively you could use a regex like
      (Align the last instance of { on each line)
      without Align from caret position to achieve it.
    • I can understand that there might not be much call for this alignment feature, and your regex does the job. If you do decide to implement this option it would allow me to skip adding a new shortcut, but that's not a big deal.
      I tried to assign the macro to the backslash key (so it was near the '[' and ']' keys), but could not get it to fire. I assigned it to the 'p' key and it works as expected. Installing the 11.1 release didn't improve the situation. The issue with the backspace key may be specific to my setup.
      The option to add a space after the aligned character is something I would still find useful should you choose to implement it.
    • Hi,
      Just confirmed the backslash shortcut does not seem to work -
      For aligning the character after an alignment... Well, this can already be achieved with alignment chaining. If we create a very simple shortcut of...
      With IsRegex, and AddSpace. This shortcut simply aligns the next non-space character. We can chain this onto any other shortcut to add a space after the character of the last alignment.
    • That doesn't quite do it. Starting with this:
      var a = { {one,three,five,b}, 
      and running the regex you suggested two messages above yields:
      var a = { {one,three,five,b}, 
      which is close to what I'm trying to accomplish.
      Chaining the short regex above yields:
      var a = { {one,three,five,b}, 
              { seven,nine,five,eight},
              { ab,b,cc,z}};
      What I'm after is this:
      var a = { { one,three,five,b}, 
                { seven,nine,five,eight},
                { ab,b,cc,z}};
      I'm using a modified version of the regex you suggested on 10/31/14 to accomplish the brace alignment. Using it with the close brace version of the macro, with the 'add space' checkbox checked, I can get this:
      var a = { {one,three,five,b      }, 
                {seven,nine,five,eight },
                {ab,b,cc,z             }};
      because the 'add space' inserts the space between 'eight' and the closing brace and aligns the other braces to it. An 'add space after' would allow me to do the same thing with the opening brace.
      BTW, thank you for your excellent support!
    • Hi,
      What I'm suggesting is a two stage alignment with alignment chaining. Let's say you set '1' to 
      with IsRegex on
      then set '2' to
      with FromCaret, IsRegex & AddSpace on.
      then if you use the shortcut (keeping ctrl held the whole time) 
      Ctrl = 1 2
      then it would align the way you want.
    • Hello,
      Using the wonderful ",\s*(?<x>[^\s])" regex on Comma key with all checkboxes ON, I have great results, provided I set the cursor on first field before doing Comma, then going to next field and using Comma again...
      On your example let's start by cutting the first line on a new line like this :
      var a = { 
      { one, three, five, b },
      { seven, nine, five, eight },
      { ab, b, cc, z } };
      The you put cursor on "one" and do align by Key/Comma, then cursor on "three" and align by Key / Comma, then on "five" align by Key / Comma and you're nearly done :
      var a = { 
      { one,   three, five, b },
      { seven, nine,  five, eight },
      { ab,    b,     cc,   z } };
      The  use line select and tabify to put everything in shape.
      This wonderful "Comma" shortcut got me saved on a horrible array who looked like this :
      	UTF8name("obreve",	0x014F,	"", 1, FALSE),
      	UTF8name("ocandradeva",	0x0911,	"", 1, FALSE),
      	UTF8name("ocandragujarati",	0x0A91,	"", 1, FALSE),
      	UTF8name("ocandravowelsigndeva",	0x0949,	"", 1, FALSE),
      	UTF8name("ocandravowelsigngujarati",	0x0AC9,	"", 1, FALSE),
      	UTF8name("ocaron",	0x01D2,	"", 1, FALSE),
      	UTF8name("ocircle",	0x24DE,	"", 1, FALSE),
      and now looks like this:
      	UTF8name("ocandradeva",	                             0x0911,	         "",                        1,          FALSE),
      	UTF8name("ocandragujarati",	                         0x0A91,	         "",                        1,          FALSE),
      	UTF8name("ocandravowelsigndeva",	                 0x0949,	         "",                        1,          FALSE),
      	UTF8name("ocandravowelsigngujarati",	             0x0AC9,	         "",                        1,          FALSE),
      	UTF8name("ocaron",	                                 0x01D2,	         "",                        1,          FALSE),
      	UTF8name("ocircle",	                                 0x24DE,	         "",                        1,          FALSE),
    • By the way MSDN automatic line formatting doesn't give justice to the plugin work :-)
  • Aligning on parens
    3 Posts | Last post January 27, 2015
    • I have a macro that aligns opening parens assigned to the '[' key.
      Given the following code
      When I place my cursor anywhere on either line before the first set of parens and press 'Ctrl = [' I get:
         kernel.Bind<IDiscountHelper> ().To<DefaultDiscountHelper>();
      If I then place my cursor anywhere after the first closing paren on either line and again press 'ctrl = [' nothing happens and the parens at the end of the statements do not align.
      If, however, I chain the commands by holding the ctrl key down and pressing '= [ [' the statements align as I expect:
         kernel.Bind<IValueCalculator>().To<LinqValueCalculator>  ();
         kernel.Bind<IDiscountHelper> ().To<DefaultDiscountHelper>();
      Can you tell me why the 1st method doesn't work but the 2nd (using chaining) does?
    • Again, sorry for the late reply.
      Just checking does the shortcut have the "From caret" tick box ticked?
    • Thanks! The checkbox was not checked; checking the box fixed the problem.
  • Shift key reassignment
    3 Posts | Last post November 05, 2014
    • Since the shift key is used to restrict the alignment to 'from caret', I am unable to align by curly braces, parenthesis or other shifted characters.
      Is there a way to assign another key to this function, or to align by a shifted character?
    • Hi Casterle,
      I feel you have a misunderstanding on how code alignment works. Ctrl = Q for example won't automatically align all Qs. You have to tell it what Q means. To code alignment a key is just a key. You must map it. There's a handful of default mappings (which you can change)
      You might want to consider mapping {[ to the regex (\{|\[) which will align all instances of { or [
    • You're right, I was under a misapprehension. Thanks for clearing that up.
  • Custom command in toolbar
    3 Posts | Last post October 23, 2014
    • By default, it shows '=, ==, m_ etc' command in the toolbar, is there a way we can add custom command other than by going to 'Align by..'? 
    • Hi Sanjeev,
      Keyboard shortcuts can be customised -
      As for the toolbar, to be honest once you start using the shortcuts the toolbar it pretty useless. However, all buttons on the toolbar (except ==) points to a shortcut. So if you for example changed the M alignment to what you want, and then use another extension to change the icon. 
      But I suggest using the keyboard shortcuts.
    • Thanks :)
  • Align after public type
    3 Posts | Last post July 23, 2014
    • This is a great tool, it is going to save me a lot of time, but I am having a problem with 
      In the case where I want to align...
        public string FirstName { get; set; }        =>  public  string  FirstName { get; set; }    
        public string Surname { get; set; }          =>  public  string  Surname   { get; set; }
        public int Age { get; private set; }         =>  public  int     Age       { get; private set; }
        private Address Address { get;  set; }       =>  private Address Address   { get; set; } 
      Can not get automatic alignment of FirstName, Surname with Age and Address
      What I am thinking is needed is an alignment of white space separated text for N columns.
      Currently I only get the alignment to work by manually entering spaces.
      Using VS 2013 with code alignment tool downloaded yesterday
      Yes I have looked at
      Thanks for this great tool!
    • Hi Pi
      I always format my auto properties exactly the same way you do.
      "Align by space" is the answer, albeit a multi-step process. In a nutshell, you're aligning each column by space, one column at a time. "Align by space" only aligns to the right of the current caret column position.
      I normally click somewhere near the middle of the first column, lets say the caret is now on the second line, between the 'b' and 'l' in the word "public". Hit Ctrl+=, space.
      Move the caret with the mouse or keyboard so that it is somewhere within the shortest word of the next column. In this case the word "int" is the shortest, so lets say the caret is now just after the 't'. Hit Ctrl+=, space.
      Again , move the caret to the column that is within the smallest word of the next column: "Age". Hit Ctrl+=, space.
      This takes a long time to read, but in practice it literally takes about four or five seconds to do align three columns. And you might have 20 lines of auto properties.
      Kind regards
    • Hi Michael,
      Yes thank you - got it.
      Yes it is fast (once you know what you are doing).
      Thank You :-)
  • auto property alignment
    2 Posts | Last post May 07, 2014
    • is it possible to align
      public int Id { get; set; }
      public String Name { get; internal set; }
      public Dictionary<string, string> Data { get; protected set; }
      public int                           Id   { get; set; }
      public String                        Name { get; internal set; }
      public Dictionary<string, string>    Data { get; protected set; }
    • Hi, Sorry about the delay.
      This can be done using "Align by Space" Check out
  • waiting for second key of chord
    4 Posts | Last post November 27, 2013
    • How can I fix this?
      When I press CTRL + =, I see "waiting for second key of chord" .. 
    • It is possible to do this?
      align to
      position: relative;
      top:      0;
    • Hi Polikin. Visual Studio defines a chord as a series of key presses (like on a piano). For example to toggle "show white space" you press Ctrl E, S - when you press Ctrl E in the status bar it will say "Waiting for second key of chord"
      I used the same terminology for code alignment. Ctrl = activates Code alignment, then you enter the next key, for example, pressing = again will align by equals.
    • To do that alignment press Ctrl Shift =, click the options button and choose "Shortcuts"
      Add a shortcut, for the alignment put
      (explanation: the (?<x> identifies the part to align by,if it doesn't exist it groups at the start, the \s means white space, so it says, "align by the first non space after a colon")
      tick "Is Regex" and "Add Space" and use what key you assigned it to as the second key of the chord.
  • C# format document deletes all spaces
    6 Posts | Last post November 07, 2013
    • I'm using VS2013 C#.
      It's happy to alignment all the enums for me.
      But after save, all of them revert back to unalignment state...
      Then I tried Ctrl-ED, it also do the same thing...
      I tried to disable maybe related components include CodeMaid, VScommands, Web Essential, with no luck.
      I also tried to look for any settings that may affect this, also with no luck.
      I'm heavily rely on format document function too, and love to use CodeMaid cleanup/format on save.
      That means Code alignment do nothing to me!
    • Hi there,
      If you are formatting a document on save then there's little Code alignment can do.
      The purpose of Visual Studio's format is to fix the indentation, add spaces when they are missing (foo=bar to foo = bar) and to remove duplicate spaces when they are not needed.
      This means that it's purpose is to remove what code alignment inserts.
      For me, I turned off every automatic format trigger. The things it fixes were things I never did (I always indent properly, always have spaces around = signs, etc) so the only thing it did was annoy me by undoing things that I wanted to keep.
    • As to why it's auto formatting on save, I can only guess that you still have an extension enabled. The default Visual Studio behaviour does not format c# on save.
    • I still wish to use format on save.
      Sometimes I will do some lazy editing, and while saving, all of them will be corrected.
      And sometimes only because team member's code is not well formatted (cause they doesn't use format on save). I don't need to check, just use CodeMaid's "Cleanup All Code" occasionally to correct all of them.
      And wish to keep the alignment that I do purposely.
      If you can find out the VS setting for removing space, I can disable it.
      Or your add-in can affect the process of formatting, never to remove the spaces that code alignment inserted.
      Or you can insert a different space char, that seems the same as normal space char, and won't be remove by formatting.
      From now on, I can only uninstall code alignment, until you can do something to the users using Ctrl-ED/format on save.
    • "If you can find out the VS setting for removing space, I can disable it."
      No setting exists in Visual Studio
      "Or your add-in can affect the process of formatting, never to remove the spaces that code alignment inserted."
      There's no way to determine if extra spacing is for an aligning or a mistake - and to put it bluntly, there shouldn't be. Modifying the process is impossible, you could override it, but that's not in the scope of code alignment and again, it shouldn't be.
      "Or you can insert a different space char, that seems the same as normal space char, and won't be remove by formatting."
      This is not an option. If a character like that existed (And I'm not familiar enough with Unicode to say if it does or not) You'd run the risk of an editor not being able to display it properly, a compiler treating it as a meaningful character and showing an error people can't figure out - because the cause is completely hidden.
      The only possibility is for a separate extension which overrides the format document call, and never removes any spaces. Personally, I think such an extension would render the format command useless.
      If you want to use the format command and code alignment, you need to take it off the save event. The keyword in your description of why you format is SOMETIMES. On the few cases when this happens, then format your document or section.
    • Code alignment is going the extra mile; it's the opposite of the lazy option, like auto-format on save. It's about taking pride in your work and making your code beautiful to look at and easy to read. It's about helping the next guy understand your code. (And sometimes the next guy is you, two years down the track.)
      An auto-format tool will make your code consistent, but it will be consistently awful to look at. The only way to make really neat code is to do it yourself, which is where the Code alignment extension shines.
1 - 10 of 31 Items