How to disable all whitespace autoformatting in Visual Studio 2015?

前提是你 提交于 2019-11-28 20:26: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.

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

Go to Tools -> Options.

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.

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.

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

edit- since question has actually changed

To reduce the incidents of autoformatting, uncheck options like these:

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

Disable virtual space

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

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. :-)

You are going to have to get used to the way auto-format works in the editor. You are starting a machine that takes code very literally. It works like a compiler does, doing what you said, not what you meant.

And the only option you have available right now to get it to not mess with your spacing is Text Editor > C# > Formatting > Spacing > Ignore spaces in declaration statements option. There are no other "ignore" options. And there is no magic character or escape that tells it to ignore a specific statement.

Which works just fine for the snippet you posted. You didn't give a example of where you want it to behave differently but if it is not a declaration then you'll know what happens. The C# IDE team is always very interested in concrete and practical proposals to make the editor work better. You'll have to think of one first. Heavy emphasis on concrete and practical, something that requires "artificial intelligence" or changes to the language is unlikely to fly. The outcome has to be reasonably predictable and it can't cost a lot of cpu cycles. You can post your proposal at connect.microsoft.com or (probably better) at github for the Roslyn project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!