Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Visual Studio 2013 from automatically removing extra spaces in assignments

I'm trying to align some assignments to improve readability, but each time I paste something, Visual Studio 2013 automatically removes the extra spaces before the =.

For example, this:

static class Constants {
    public static string Something      = "A value";
    public static string SomethingElse  = "Another value";
}

gets re-formatted like this:

static class Constants {
    public static string Something = "A value";
    public static string SomethingElse = "Another value";
}

Is there a way to turn this off?

like image 221
Paolo Tedesco Avatar asked Mar 03 '15 14:03

Paolo Tedesco


People also ask

How do I stop Visual Studio from auto formatting?

If you are using ReSharper auto-formatting features, we recommend that you disable Visual Studio auto-formatting. You can do it in Visual Studio options (Tools | Options). For C# for example, clear the corresponding check-boxes on the Text Editor | C# | Code Style | Formatting | General options page.

How do I get rid of extra spaces in Visual Studio?

Well, place the cursor into the line from where you want to clean it up and then navigate to Edit -> Advanced -> Delete Horizontal White Space or press Ctrl + E , \ . That will automatically remove the additional spaces from your code.

How do I change the format in Visual Studio?

To access this options page, choose Tools > Options from the menu bar. In the Options dialog box, choose Text Editor > C# > Code Style > Formatting.


2 Answers

This can be turned off in Tools->Options->Text Editor->C#->Formatting->Spacing via the "Ignore spaces in declaration statements" option.

enter image description here

like image 182
Cameron Avatar answered Sep 17 '22 20:09

Cameron


VB.net for VisualStudio 2016 instructions:

|<-- main menu bar -->|<------------Side Panel Of Options Window------>|
Tools --> Options --> | Text Editor v | --> | Basic v | --> | Advanced |

    Options.Advanced window:
 =========================================================  
 =   +----Highlighting-------------------------------+   =
 =   | (...)                                         |   =
 =   +-----------------------------------------------+   =
 =                                                       =
 =   +----Outlining----------------------------------+   =
 =   | (...)                                         |   =
 =   +-----------------------------------------------+   =
 =                                                       =
 =   +----Editor Help--------------------------------+   =
 =   |                                               |   =
 =   | [ ] Pretty listing (reformatting) of code     |   =
 =   |                                               |   =
 =   +-----------------------------------------------+   =
 =========================================================

Screen shot: enter image description here

like image 34
Juan Marco Avatar answered Sep 19 '22 20:09

Juan Marco