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?

2
  • 1
    I'm not sure the feature, but you can press ctrl+z immediately after pasting to get the original formatting back.
    – Matthew
    Mar 3, 2015 at 14:46
  • 1
    @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 :) Mar 3, 2015 at 14:49

2 Answers 2

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

3
  • No problem :-) Seems there's only an option for declarations though, not assignments in general. Ah well.
    – Cameron
    Mar 3, 2015 at 14:51
  • Yes, it would be nice to have some more "ignore" options. Mar 3, 2015 at 14:57
  • 1
    While this should work, it does not appear to have the desired effect as Format Document still removes extra blanks and tabs Apr 5, 2017 at 9:26
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.