Stop Visual Studio 2013 from automatically removing extra spaces in assignments
Asked Answered
M

2

8

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?

Monarchal answered 3/3, 2015 at 14:44 Comment(2)
I'm not sure the feature, but you can press ctrl+z immediately after pasting to get the original formatting back.Sanskritic
@Matthew: yes, I know, but it's quite annoying to have to undo every time... moreover, I would still like to be able to format the document (ctrl-k, ctrl-d) without all alignments exploding :)Monarchal
S
13

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

Shithead answered 3/3, 2015 at 14:49 Comment(3)
No problem :-) Seems there's only an option for declarations though, not assignments in general. Ah well.Shithead
Yes, it would be nice to have some more "ignore" options.Monarchal
While this should work, it does not appear to have the desired effect as Format Document still removes extra blanks and tabsStriper
C
3
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

Clerihew answered 21/9, 2016 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.