Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

c# - How to disable all whitespace autoformatting in Visual Studio 2015?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...