Turn off auto formatting in Visual Studio

假装没事ソ 提交于 2019-11-26 06:00:26

问题


I\'m a code purist, preferring my own style of code formatting as opposed to Visual Studio\'s default settings. I\'ve turned off auto-formatting options in Tools/options. In most cases it works.

After using any of the built-in refactorings, Visual Studio clobbers my settings with its default settings. How do I keep VS from doing that?


回答1:


I had this problem while writing VB in an aspx page.

The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty Listing' OFF.


Note - in Visual Studio 2015 this can be found at:

Tools > Options > Text Editor > Basic > Advanced




回答2:


Disable pretty listing. It is the option that re-formats what you are doing. I had the same discomfort with it and after doing it, my code stays how i want and it doesn't go back to previous settings.




回答3:


You might have had Power Tool installed.

In this case you can turn it off from 'Tools > Options > Productivity Power Tools > PowerCommands > General'




回答4:


In my case, it was ReSharper.

Test if ReSharper

StackOverflow: How can I disable ReSharper in Visual Studio and enable it again?

Prevent ReSharper from reformatting code

StackOverflow: Is there a way to mark up code to tell ReSharper not to format it?

Update

It was ReSharper in the end:




回答5:


In VS2017 you can change it after selecting your coding language in the settings menu. There is an option called "new Lines" in the "Formatting"-submenu.




回答6:


As suggest by @TheMatrixRecoder took a bit of finding for me so maybe this will help someone else.

Unitick these options to prevent annoying automated formatting when you places a semicolon or hit return at the end of a line.




回答7:


I doubt that you can disable re-formatting after refactoring. Refactoring changes code and since it's only text I doubt what you'd want is that it just dumps unformatted text into your source. Wouldn't it be a little easier to just set the code style VS adheres to to the style you like and follow?




回答8:


The reformat on semicolon or closing brace cannot be turned off. I find it infuriating the Microsoft would have the temerity to tell anyone how to format code; the most illegible code I have ever seen was while working there.

I want adjacent assignments to be vertically aligned; VS reformats them to one space on either side of the equal sign irrespective of the length of the variable on the left. This is intolerable. And turning it off on the editor options is ignored; given comments like the opener above I am certain this is deliberate.

Consistency is only a virtue when it leads to desirable outcomes. This is not one.




回答9:


VS2015 settings that helped me prevent auto formatting:

(and Tools > Options > Text Editor > Basic > Advanced, just like Tango91 suggested)




回答10:


Follow TOOLS->OPTIONS->Text Editor->CSS->Formatting Choose "Compact Rules" and uncheck "Hiearerchical indentation"




回答11:


It can be the case of Clang Format. Previously, the entire file is automatically formatted on file save, and it drove me nuts (for the repositories which Clang Format is not enabled).

Such behavior is gone after turning "Tools -> Option -> LLVM/Clang -> ClangFormat -> Format On Save -> Enable" to False.




回答12:


You can tweak the settings of the code formatting. I always turn off all extra line breaks, and then it works fine for how I format the code.

If you tweak the settings as close as you can to your preference, that should leave you minimal work whenever you use refactoring.




回答13:


In addition to Tango's answer for the actual solution, there may be people actually want to stay current with auto-formats but not have it screw up your relevant changes. I would suggest that you modify the file to have auto-format activate, check in those changes, then proceed with the actual changes you wish to make.

That way your code can stay up to date, but your check in will be relevant.




回答14:


Try disabling the extension Bundler & Minifier



来源:https://stackoverflow.com/questions/737222/turn-off-auto-formatting-in-visual-studio

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