A long time ago (about 3 years now) a bug was opened on the Microsoft Feedback site regarding how Visual Studio removes tabs in statements (which prevents using Tabs or spaces for aligning fields and locals in declaration statements).  This wasn't true in VS 2003, but started happening in VS2005 with the new formatting engine.

For example, the following statements:

int               index                =    5;
string            text                 =    "blah";
string            reallyLongVarName    =    "foo";
LongTypeName      bar                  =    new LongTypeName(5, 7, 3);

Would become:

int index = 5;
string text = "blah";
string reallyLongVarName = "foo";
LongTypeName bar = new LongTypeName(5, 7, 3);

We weren't able to add full alignment options (individually control how symbols are aligned in the editor) in VS2008, but recently addressed the scenario of aligning in declaration statements.  The design was iterated on with a few customers from the Microsoft Connect site (thanks!).

 

Here's what you'll see in VS 2008:

A new option was added to Tools | Options | Text Editor | C# | Formatting | Spacing | Set other spacing options.

The option is a check-box and says: “Ignore spaces in declaration statements”.

The option applies for :

  • Constants and Fields
  • Local variables

The option will apply for every location that a field or local variable is valid, including:

  • Block
  • For-statement
  • Foreach-statement
  • Using-statement

If the option is on, we will retain the users spacing around attributes, modifiers, type, identifier, and the binary operator, however we will continue to format spacing within the right-hand-side expression.

type                                                     identifier         =        expression;

attribute        field-modifier         type        identifier         =        expression;

Spacing between multiple statements will continue to be removed.

For example, the following:

int     index   =   5;      string      text    =       "blah";

Would become:

int        index    =     5; string         text      =         "blah";

 

We will continue to not format around comments.

This is in the builds after Beta 2.

Let us know what you think!

 

Happy coding,

Karen