Turn off auto formatting in Visual Studio

Viewed 155072

I prefer 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.

However, 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?

17 Answers

As suggest by @TheMatrixRecoder took a bit of finding for me so maybe this will help someone else. VS 2017 option can be found here

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

VS2015 settings that helped me prevent auto formatting:

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

enter image description here

I see that many answers here solve the problem for a specific situation.

For my situation I continually found that the IDE would automatically format JavaScript code within an ASP page.

To disable, I unchecked this box: enter image description here

In addition, I found it very helpful to use the search query in the toolbar (CTRL+Q) and just search for the text format on paste. As you can see with the scroll bar, there are quite a few options to check!

enter image description here

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?

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.

ClangFormat Format On Save

I was pissed off every time I pasted anything in cshtml file in Visual Studio 2015, 2017. I tried different settings and finally found the proper one: Options => Text Editor => HTML => Advanced => Paste (Format on paste) => False enter image description here

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.

You might need to check on Tools-> Options-> Xaml Styler -> Format xaml on save

enter image description here

On the navigation options at the top select "Tools" and then select "Manage Extensions".

I had CodeMaid, Visual Assist, and Rosalyn installed. Seems like an update start to cause these auto formatting issues. I disabled them and do this fixed it.

Related