26

I really like the new Visual Studio 2015, but the auto formatting is a bit too much extensive for my liking. Especially I like to have control over whitespace:

public class TipStats
{
    public int      Points          { get; set; }
    public int      Position        { get; set; }
    public decimal  Percentage      { get; set; }
}

I only see three autoformat settings in my settings, and I have ticked them all off - still Visual Studio is autoformatting my whitespace.

enter image description here

Are there any other hidden settings that I need to know for disabling all whitespace autoformatting?

Update As @Saragis notes Ignore spaces in declaration statements works sometimes for this specific example, but still there all kind of autoformat forces working against what I want.

Most options seem to only define how you want your autoformatting. I'm looking for the setting that defines if you want autoformatting.

PS: I'm having only problems with autoformatting I still use CTRL+K, F to manual format parts of my code now and then.

Update - Added feature request on UserVoice

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/9795837-add-an-ignore-space-for-all-format-options

Dirk Boer
  • 7,007
  • 9
  • 49
  • 89
  • Is the option under _Formatting_ > _Spacing_ > _Ignore spaces in declaration statements_ what you're looking for? – Saragis Aug 26 '15 at 15:15
  • Hi Saragis, thanks for your comment, but didn't work.. – Dirk Boer Aug 26 '15 at 19:10
  • 1
    Hi, can you explain the down vote so I can update my question? – Dirk Boer Sep 08 '15 at 10:08
  • 1
    You got downvoted, because there are some people, who think, that your approach to code formatting is not proper. Obviously when you create code on your own, formatting doesn't matter. It will be only you, who sees code. But if you enter team, where different people have different view on what looks good, and what looks bad, it will be a huge problem. if you just adjusted to standard code formatting, which is well defined for C#, you wouldn't have these kinds of problems, and you wouldn't waste time asking here. And remember to eat broccoli, it is healthy. – LukLed Sep 13 '15 at 11:11
  • 8
    I will @LukLed, thanks for the broccoli tip! ;) about the rest of what you say: if people really downvote because they don't like a particular style that's pretty sad. I would say there is a pretty good case for vertical alignment, but that's out of the scope of this question and forum. – Dirk Boer Sep 13 '15 at 12:33
  • 1
    Your style may be the best style in the world. I am not saying it is or isn't. It doesn't matter. What matters is that it is different from standard. Convention over configuration also applies to code formatting :) – LukLed Sep 14 '15 at 09:34
  • 2
    @LukLed If the standard formatting was so important, there wouldn't be options to change the formatting, right? Even with the standard formatting, the code can become f***** unreadable, at least as soon as you have many function arguments or large type-ids due to generics. And then you'd be happy, if you could format the code differing from the standard, imho. – MABVT Oct 01 '18 at 05:30

4 Answers4

16

I realised I misunderstood the question in my original answer, so have added a partial answer disabling autoformatting for white space.
If you select ignore white space on all options where it is offered, it will not reformat the white space of those areas of code.

enter image description here

These screen shots are taken from VS2015 Enterprise.
I'm starting from the beginning to help anyone who lands here.

Go to Tools -> Options.

enter image description here

Scroll down to Text Editor. It's worth clicking through the all the general tabs. And the All languages tabs. There are some shared formatting settings that can be set, like line wraps.

enter image description here

Then go to the languages you wish to customise (I'm showing C#) and click on formatting. There you will find options, I have expanded the spacing one, as per the title of your question.

enter image description here

Then you can explore each of these tabs to customise your format for each language.

enter image description here

edit- since question has actually changed

To reduce the incidents of autoformatting, uncheck options like these:
enter image description here

The only way you can manage the autoformatting is to play with these settings. You can also use regex with find and replace to remove space from files, but do so carefully. Beyond these tips to customise your autoformatting, to reduce VS process of autoformatting and to manually autoformat, that's all I can think of.


There is also this: Under Edit -> Advanced -> Delete Horizontal White Space

enter image description here

  • 1
    Hi @Heyyou, thanks for your extended answer. I went through all these options and tried to come closest to what I want that is possible - still the autoformatting seems to often try to do correct things that I don't want. Most options seem to dictate **how** you want to your autoformatting - not **if** you want autoformatting. – Dirk Boer Sep 12 '15 at 10:56
  • Hi @Heyyou, as you can see in the history I just made an extra statement to make the question more clear - as apparently it became misunderstood. I still think my changes reflect the title *How to disable all whitespace autoformatting in Visual Studio 2015?* and the main body of the question. – Dirk Boer Sep 12 '15 at 17:56
  • Hi @Heyyou I've awarded you the bounty for your extended answer, because I think it will really help people. I don't 'officially' accept the answer though, because there is even following these instructions still 'white-space autoformat magic' going on. I try to make a case for that and submit it to the VS team. Thanks for all your help though! – Dirk Boer Sep 16 '15 at 07:27
  • @YvetteColomb Sorry, this is totally unrelated, however, you seem knowledgeable about the subject. Is there a way to disable alignment in blank lines? In older VS when you clicked on a blank line the cursor fell all the way to the left. Now it stays up to the current block indentation. This is somewhat like limited virtual space. – the swine Mar 28 '17 at 20:37
  • @Yvette Colomb thanks for this post , i was looking same thing from long ,looking like it will help me . i need to stop removing Empty lines in my VS 2015 . – Vivek Shukla Jun 27 '17 at 06:49
  • @Yvette Colomb i am referencing my issue , please look ,it looking ,this is something for what i am wandering . https://stackoverflow.com/questions/44747909/visual-studio-update-model-from-data-base-issue/44772280?noredirect=1#comment76526844_44772280. – Vivek Shukla Jun 27 '17 at 06:54
4

The answer from Yvette Colomb is fine, but it does neither work on declarations inside functions, nor on enums (where in my opinion it is needed most).
Thus I had the idea to just add a comment between the variable and the operator, which simply breaks the obvious rule "set exactly one space character between variable (or enum name) and operator (=)", because there is no operator following the variable any longer! Not very nice, but also not too bad and IMHO it has definitely more advantages than disadvantages. :-)
enter image description here

Tobias Knauss
  • 2,931
  • 1
  • 14
  • 39
1

Disable virtual space

Virtual space is a headache, please disable it int Tool>Options>Text Editor>C#>General. Life is better.

  • 1
    Hi! Thanks for taking the time to contribute an answer. Your answer could really use some context or explanation about what Virtual Space is and does. Please take a look at our [guidelines on how to write great answers](https://stackoverflow.com/help/how-to-answer). – Carles Alcolea Mar 21 '20 at 06:00
0

For the last version of Visual Studio :

Go Preferences :

enter image description here

Go Source code > C# :

enter image description here

Set Policy to custom :

enter image description here

Go C# format and tap on edit :

enter image description here

Set like me the New Lines :

enter image description here

And voila.

YannSteph
  • 9,590
  • 3
  • 49
  • 46