How do I turn off auto-formatting in VS2013 for C++?

34,490

Solution 1

You can turn off automatic C / C++ /C# code formatting by going to the Options dialog from the Tools menu, selecting the Text EditorC / C++ / C#FormattingGeneral page, and unchecking all the boxes there. You'll still be able to manually format when all of the auto-formatting settings are turned off.

enter image description here

Solution 2

I know this isn't exactly the answer you're looking for, but you can preserver that void f () formatting if you go to Tools > Options > Text Editor > C/C++ > Formatting > Spacing and under Spacing for function parantheses you check the option Insert space between function names and opening parentheses of argument list.

Solution 3

I also had this problem and unchecking all the checkboxes in the formatting options did not help.

It turned out that this was caused by an option in the plugin “Visual Assist X” from Whole Tomato Software.

In my case this problem could be solved by going to “Visual Assist Options”-->”Corrections” and unchecking the Checkbox “Format after paste”.

Solution 4

Just remember that resharper can also override the indentation/formatting settings. You can turn that off by doing this

ReSharper -> Options -> Environment -> Editor -> Editor Behaviour -> Auto-format on closing brace (un-check this).

enter image description here

Solution 5

It's a bug in VS 2013 beta that it cannot be turned off completely, see issue submitted by FuleSnabel: http://connect.microsoft.com/VisualStudio/feedback/details/797716/turning-off-auto-formatting-for-vs2013-c-only-seems-to-partial-disable-auto-formatting. Some possible workarounds:

  1. If you just peek into some projects which have different/weird style: if an unwanted auto-formatting happens, then you can perform one undo step, this should undo only the auto formatting part of the operation and not your contribution. Fortunately these two (or sometimes more auto formatting steps) are not grouped together into one command probably for this exact reason: you can go back and override it. It is annoying though if that happens all the time. You can configure the behavior to match your style, but you say you have project with different code styles.
  2. Tools/Import and Export Settings... - you can export the specific settings for a certain project and then import it later. This will save .vssettings XML format file. If it's about just a specific file type, than it can be just a few kilobytes long. Unfortunately this requires manual steps. The best would be if these settings could be overridden from the solution configuration file or even the project configuration file, could be part of them.
  3. Note, that this second point is problematic if you really work parallel in your projects with simultaneously open Visual Studios. In this case that settings will be saved finally what the last closed VS instance had I think.

Having different auto formatting saved for solutions can be a feature request for next release (certainly not make it to VS 2013). What I usually come across is the tab/space indentation behavior differences, it's the most common difference in project styles. Indentation also can be configured individually for most file types, but as as in your case, projects can differ, and then it becomes annoying.

Share:
34,490
Just another metaprogrammer
Author by

Just another metaprogrammer

All code posted by me on StackOverflow is dual licensed: cc by-sa 3.0 with attribution required (StackOverflow standard License) Apache License version 2.0 Pick the License most useful to you if you decide to use code I posted.

Updated on November 08, 2020

Comments

  • Just another metaprogrammer
    Just another metaprogrammer over 3 years

    VS2013 has added auto-formatting for C++. My personal opinion on auto-formatting is that it's ultimately harmful for developers but I have to accept not everyone agrees. What bugs me is that I can't seem to disable auto-formatting completely. I have unchecked every checkbox under Tools->Text Editor->C/C++->Formatting->General yet when I type:

    void f ()
    

    VS2013 replaces this with

    void f()
    

    That's not the code-standard in this specific project which means I have to go back and insert a space. There are other examples where I have to fight against VS.

    I don't want to change the spacing settings because

    1. I work in multiple projects with different code standards
    2. I don't believe in auto-formatting so I just want it to get out of my way

    I just want VS to not modify my code automatically.

    PS. I am not against that VS can format code but I want to invoke that manually

  • Just another metaprogrammer
    Just another metaprogrammer almost 11 years
    Thanks. No, I am aware of that I can change the code-style settings but my problem is that I contribute to multiple projects with different settings. It's a pain to switch back and forth. I just want to disable auto-formatting. In the end I might have to do what you suggested if I can't turn it off.
  • Ben Voigt
    Ben Voigt almost 11 years
    That was mentioned in the question.
  • Just another metaprogrammer
    Just another metaprogrammer almost 11 years
    That's is what I thought as well, but VS2013 refuses to stop auto-format code like: f () into f().
  • Admin
    Admin almost 11 years
    This turns out to be a bug in the Visual Studio 2013 Preview - auto-formatting is always being run when brace/parenthesis completion occurs. We're adding a new option to configure this behavior. Thanks for pointing it out.
  • Just another metaprogrammer
    Just another metaprogrammer almost 11 years
    Thanks for your response. Now I am little bit uncertain on what do wrt to marking a response as the answer.
  • Just another metaprogrammer
    Just another metaprogrammer over 10 years
    As this is now fixed in VS2013 RTM this is the correct answer.
  • Assimilater
    Assimilater almost 8 years
    There isn't a box for "when the file is saved". Is there a way to turn that off, but keep the auto-format on curly brace, semi-colon, etc?
  • bh_earth0
    bh_earth0 over 5 years
    thanks also there json formmating thats annoying in vs2017 coloring ok nice but. i want to keep it indenting style myself
  • CashCow
    CashCow over 4 years
    It isn't fixed for me. Where's the patch?
  • CashCow
    CashCow over 4 years
    I have everything unchecked. Type my constructor, next line tab, colon for initializer list and VS moves it to the start of the line. PLEASE DO NOT MOVE WHERE I TYPED IT.