Code alignment


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

(55) Review
Visual Studio
2013, 2012, 2010
Download (88,104)
E-mail Twitter Digg Facebook
Add to favorites
Reviews (55)
Q and A (25)
Sign in to write a review
Sort by:

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 Sun 11:27 PM
| 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!

by Kat_Development | October 16 2013

by johnm9 | October 15 2013

by dave_s123 | October 14 2013

by __Kerry__ | October 11 2013

by dagope | September 08 2013

Must-have! Now my code is more readable

cpmcgrath October 29 2013
| Edit |

Great to hear you're enjoying it!

by Rahul Techie | August 06 2013

by Paiden36 | June 22 2013

Simply amazing. Use it every day. Thanks for your efforts.

by omoridi | May 25 2013

I like that

by D. Chatterjee | May 20 2013


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

  • 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.
  • Align By Tab or Align By RegEx
    12 Posts | Last post October 18, 2013
    • Hi, good tool!
      I would like to see a way to 1) align by Tab (yes, I know you hate tabs) since I don't see a way to enter a tab, or 2) align by a regular expression which would seem to make the tool even more versatile.
      Good work.
    • Love the idea of allowing regular expressions. I won't implement the align by tabs directly but the align by regular expression should allow you to do that.
    • +1!
    • When the "Use IDE tab settings for alignments" is checked, the alignment ends up with mixed spaces and tabs for some reason. I wish this could produce pure tab alignment rather than mixed with spaces. Also, this yeilds JHint warnings.
    • +1 for tab support; it should honor the vs setting not impose a personal preference on the users. I wouldn't be permitted to commit space-aligned code so cant use.
    • There is support for tabs via the "Use IDE tab settings." This is not on by default because lots of users requested it. They saw tabs was used for indentation, while spaces should be used for alignment.
      Personally, I believe that the basic idea of tabs conflicts with aligning code. A tab has no true size, if you align with tabs then someone else reads the code and they display at a different tab size, then there is a very good chance the code won't be aligned for them. This is a conflict in the very core concepts. Tabs are about allowing individual developers to view the code how they want. Alignment is about specifying exactly how it should be displayed.
      The only way to assure it stays the same is to make sure everybody uses the same size tabs in which case, why bother with tabs at all?
    • I can't believe some companies insist on tabs. If I was in a job interview and the interviewer told me that, I'd say, "Thanks for your time, but this job isn't for me." It's not just about tabs; a rule like would mean the company has lots of other terrible policies, too.
      A millimetre is always a millimetre. One space is always one character wide. How many characters is a tab? 2? 4? 8? Tabs really only work properly if everyone uses the same tab size. Which kind of defeats the purpose.
      What if your boss said, "From now on set your tab size to seven, my favourite number. It's the number of 'completion' and I was born on the 7th, ya know."
      Seriously: Tabs Are Evil.™
    • Thank you for your comment cpmcgrath, I didn't notice the options box! I don't believe the alignment works in tab mode though.
      starting with (nonsense) code:
      			1 = 1;
      			22 = 11;
      			333 = 333;
      			666666 = 666666;
      Alignment gives me:
      			1 	   = 1;
      			22 	   = 11;
      			333    = 333;
      			666666 = 666666;
      whereas I believe it should be: (dependant upon tab-size setting of course)
      			1		= 1;
      			22		= 11;
      			333		= 333;
      			666666	= 666666;
      i.e., the alignment seems to be achieved by inserting a mix of tabs and spaces, rather than just tabs.
    • I get what you're saying, and I'm sure there are a lot of people who agree with you. But I think there's as many people who would say the exact opposite.
      It could be an option but I'm very reluctant to add anything new about tabs, as I've said tabs and alignments on a fundamental level does not make sense. As such adding new features for tabs adds little value, and I'd prefer to spend my time on bigger things.
      Code alignment is open source, and if someone submitted a patch for this, and I was happy with the implementation I would add it to the project.
      I've expanded on my reasons above here -
      I strongly recommend reading it, and reconsidering the reasons why you prefer to align with tabs.
      You said that your team has standardised on tabs. Do you all use the same tab size? Because if you don't, then your alignments won't be aligned for everyone - if you use spaces they will.
    • Hi, thanks for replying. I have read the reasons but tbh I don't get excited about the tab vs spaces debate, I stopped taking on theological code formatting debates many years ago, nobody wins when the coding evangelicals are in the room – there is no wrong or right way, just different ways. That said, I think it should either use tabs or spaces – not a mixture of both. I've worked in software for a long time (decades now!) and have yet to meet the coder who starts aligning his equals with tabs but finishes the alignment with spaces. Just reflecting on my experience, I appreciate you see things differently.
      (Yes, tab sizes are defined in our coding standards btw)
      My own personal opinion is I don’t care what the standard is, as long as it can be automated. Life’s too short to worry about how many times you hit the tab button (or space-bar * 2/4/8 if you're a 'space cowboy').
    • The case for using both isn't so much I want to use tabs and spaces, but this is where I want them to align at. I'll occasionally use the tool know that the furthest thing I want to align by is in the middle of a word - I don't want the word split into two.
      And it's actually a much harder change than it would seem. To insert an extra tab instead of those spaces, yeah that's easy. But then there's the issue of should it remove spaces (you write a = x not a\t= x. Should it just be a \t= x?), there's again arguments one way and the other.
      And currently Code Alignment never deletes anything (Though many people, myself included, want So it will require figuring out a consistent way to do that in Sublime, Notepad++ and Visual Studio.
    • I've created a github issue for this. Please use the issue to discuss the issue instead of here.
  • Align by space and quoted strings
    3 Posts | Last post September 26, 2013
    • There doesn't appear to be a way to use align by space to line up the MyEnum.blah statements in something like this.
      Frobinate(0, 100, "Cat", MyEnum.Item100));
      Frobinate(8, 110, "Mouse", MyEnum.Item110));
      Frobinate(9, 111, "Dog", MyEnum.Item111));
      Frobinate(10, 200, "Rabbit", MyEnum.Item200));
      Frobinate(11, 201, "Fox", MyEnum.Item201));
      Frobinate(20, 233, "Polar Bear", MyEnum.Item233));
      Depending on where I put the cursor I get something like this:
      Frobinate(0,  100, "Cat",    MyEnum.Item100));
      Frobinate(8,  110, "Mouse",  MyEnum.Item110));
      Frobinate(9,  111, "Dog",    MyEnum.Item111));
      Frobinate(10, 200, "Rabbit", MyEnum.Item200));
      Frobinate(11, 201, "Fox",    MyEnum.Item201));
      Frobinate(20, 233, "Polar    Bear", MyEnum.Item233));
      or this:
      Frobinate(0,  100, "Cat", MyEnum.Item100));
      Frobinate(8,  110, "Mouse",      MyEnum.Item110));
      Frobinate(9,  111, "Dog", MyEnum.Item111));
      Frobinate(10, 200, "Rabbit",     MyEnum.Item200));
      Frobinate(11, 201, "Fox", MyEnum.Item201));
      Frobinate(20, 233, "Polar Bear", MyEnum.Item233));
      What I want is:
      Frobinate(0,  100, "Cat",        MyEnum.Item100));
      Frobinate(8,  110, "Mouse",      MyEnum.Item110));
      Frobinate(9,  111, "Dog",        MyEnum.Item111));
      Frobinate(10, 200, "Rabbit",     MyEnum.Item200));
      Frobinate(11, 201, "Fox",        MyEnum.Item201));
      Frobinate(20, 233, "Polar Bear", MyEnum.Item233));
      Which I think is either dependent on being able to reject spaces inside a quoted string; or being able to do smarter alignment off the commas.
      Align by caret using hte comma comes closest; but aligning by putting space in front of the comma instead of after it looks really weird.
      Frobinate(0 , 100, "Cat"       , MyEnum.Item100));
      Frobinate(8 , 110, "Mouse"     , MyEnum.Item110));
      Frobinate(9 , 111, "Dog"       , MyEnum.Item111));
      Frobinate(10, 200, "Rabbit"    , MyEnum.Item200));
      Frobinate(11, 201, "Fox"       , MyEnum.Item201));
      Frobinate(20, 233, "Polar Bear", MyEnum.Item233));
    • Thanks for the question,
      Sorry about the delay, I normally get a notification when someone posts, for some reason I didn't get one.
      This can be achieved with a regex...
      If you look at the align by space, it's very similar. The difference is the comma at the beginning, and * instead of + because you still want to align if there is no space between the , and the word.
      With regexes if you include a group with the name x that's where the alignment happens. So this regex say
      find a comma, skip the spaces and align by the first non-space.
      I recommend going into the code alignment options and assigning it as a shortcut for Comma. (Tick all the boxes too)
    • In case anyone else is wondering how to easily do the alignment Dan wants, I think the easiest way would be to do the first two columns with 'align by space', then 'align by string' and type "My".
      'Align by space' honours the current caret position, so you would first set your caret somewhere near the open bracket, then move it over to the next column, e.g. 100, hit Ctrl+=, space. Then Ctrl+Shift+= to show the Enter String To Align dialog.
  • Right Alignment
    3 Posts | Last post September 18, 2013
    • Hi.
      How can I make a regex to put spaces in the left of the string making a right justification?
      var test1 = new Class1() {var1 = 2, var2 = 4000};
      var test2 = new Class1() {var1 = -12, var2 = 2.1};
      I made the regex below
      that will align the numbers "2" and "-12". But they aready are aligned in the left.
      I want to align the numbers in the right, inserting spaces on the left and leaving the comma aligned. Making some like this:
      var test1 = new Class1() {var1 =   2, var2 = 4000};
      var test2 = new Class1() {var1 = -12, var2 =  2.1};
      Other question. How can I make a reget to make change on all occurrences in the line? No only in the first occurrence.
    • Neither can be done as you want it. But the second could be done using Align from caret. After the first alignment, put your caret after the first, then do the alignment again with the "Align from caret" on (On any shortcut you can force it to use align from caret by adding Shift to the second shortcut key. For example, to align by equals from caret – Ctrl Equals, Shift Equals)
      I've definitely thought of both cases so they might be implemented in future versions.
    • +1. I want this feature too.
  • Installation problem
    2 Posts | Last post July 25, 2013
    • I have VS2010 Pro and VS2012 express.
      I started the vsix installer and he says it's already installed. 
      But in VS2012, i can't find the product.
      How can I select the VS version to install to ?
      best regards
    • Hi Oliver,
      Visual Studio Express unfortunately doesn't support extensions. With 2012 there seemed to be some confusion of if this still applied because it comes with an extension manager. The main reason for that was so you could get NuGet updates. I believe you can also use it to get templates.
  • German Keyboard Layout?
    5 Posts | Last post July 17, 2013
    • This extension does not really work with German keyboard layout. But the positive thing is, that the extension seems not to overwrite existing shortcuts. It would be nice to use them (without placing all shortcuts manually).
    • Not sure if my keyboard layout is the same as drunkenzealot's, but I'm using a UK layout, and there seems to be some weirdness around how the second key of a shortcut chord is labelled.
      The shortcut for aligning by " for instance, is still labelled as "Quotes", but the " character isn't in the same place on a UK keyboard as on a US one - it's Shift-2. If you happen to remember where " is on a US keyboard and press that key (which on a UK keyboard is #, or ~ with Shift), then you get the right result.
    • I just installed the extension and faced the same problem as drunkenzealot. Reconfiguring all the shortcuts is possible but unnecessarily annoying because by default, the bindings are all messed up on a german keyboard / VS. It would be great to see more international support in the upcoming versions! 
    • Hi Guys,
      Sorry I've sort of ignored this thread. Changing the visual studio shortcuts depending on region, I really don't have a clue where to begin with that. The file that defines them ( ) makes no mention of keyboard layout.
      As for the shortcuts inside of CodeAlignment, Obviously I have much more control over that. Currently I use 
      System.Windows.Forms.Key. I just output the .ToString(), except for a few special cases where I make it read better -
      Any advice on what I should be using for international support would be appreciated 
    • I've logged these problems as two issues. Please add any future information to the issues.
  • Mimic LineEmUp
    5 Posts | Last post January 31, 2013
    • The LineEmUp macro was just about perfect for my needs. You could select a block of code and run the macro, and it would line up on the first blank in the line. Then, if you ran it again on the same block, it would line up on the next unaligned blank, etc. Can CodeAlignment do this?
    • Pretty much. You can select a block (or let the extension figure out the scope for you) perform an alignment, move the caret past where the alignment is and perform the same alignment with the "Align from caret checked" (Tip: Any shortcut can become an align from caret by pressing the shift key with the second key press, eg instead of Ctrl = = you use Ctrl = Shift =)
      Hope that helps.
    • Thanks for the reply. I have been moving the cursor around to align. Just got a bit spoiled by LineEmUp. Any chance of having it added someday? I seem to recall that this addin is open source. Is that true? I'm not opposed to looking into it myself.
    • Yeap, it's open source on GitHub -
      If you can write this, I'll happily pull it back into the project.
    • Thank you. We're deep in a project right now, so it may be a while before I can get to it.
1 - 10 of 25 Items