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

2019-01-23 00:54发布

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

7条回答
Luminary・发光体
2楼-- · 2019-01-23 01:19

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.

查看更多
走好不送
3楼-- · 2019-01-23 01:29

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”.

查看更多
倾城 Initia
4楼-- · 2019-01-23 01:31

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

查看更多
Root(大扎)
5楼-- · 2019-01-23 01:35

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.

查看更多
爷、活的狠高调
6楼-- · 2019-01-23 01:40

Go to:

Tools->Options->Text Editor->C/C++->Formatting->Spacing

Then deselect or select the boxes that pertain to the code type you are writing.

查看更多
Juvenile、少年°
7楼-- · 2019-01-23 01:42

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

查看更多
登录 后发表回答