如何在 VS2013 for C++ 中关闭自动格式化?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18298072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:52:17  来源:igfitidea点击:

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

c++visual-studiovisual-studio-2013

提问by Just another metaprogrammer

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:

VS2013 为 C++ 添加了自动格式化。我个人对自动格式化的看法是它最终对开发人员有害,但我必须接受并非所有人都同意。让我感到困扰的是我似乎无法完全禁用自动格式化。当我键入时,我已取消选中 Tools->Text Editor->C/C++->Formatting->General 下的每个复选框:

void f ()

VS2013 replaces this with

VS2013 将其替换为

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.

这不是这个特定项目中的代码标准,这意味着我必须返回并插入一个空格。还有其他一些例子,我必须与 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
  1. 我在多个具有不同代码标准的项目中工作
  2. 我不相信自动格式化,所以我只是想让它摆脱我的困扰

I just want VS to not modify my code automatically.

我只是想让 VS 不自动修改我的代码。

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

附注。我不反对 VS 可以格式化代码,但我想手动调用它

采纳答案by Jennifer Leaf

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

您可以通过从“工具”菜单转到“选项”对话框,选择页面并取消选中其中的所有框来关闭自动 C/C++/C# 代码格式。当所有自动格式化设置都关闭时,您仍然可以手动格式化。Text EditorC / C++ / C#FormattingGeneral

enter image description here

在此处输入图片说明

回答by Marius Bancila

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 paranthesesyou check the option Insert space between function names and opening parentheses of argument list.

我知道这不是您正在寻找的答案,但是void f ()如果您转到“工具”>“选项”>“文本编辑器”>“C/C++”>“格式”>“间距”并在“函数括号的间距”下选中“插入”选项,您可以保留该格式函数名和参数列表的左括号之间的空格

回答by Gerhard Wonner

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.

事实证明,这是由 Whole Tomato Software 的插件“Visual Assist X”中的一个选项引起的。

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

在我的情况下,这个问题可以通过转到“视觉辅助选项”-->“更正”并取消选中“粘贴后格式”复选框来解决。

回答by Varun Sharma

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

请记住,resharper 还可以覆盖缩进/格式设置。你可以通过这样做来关闭它

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

ReSharper -> 选项 -> 环境 -> 编辑器 -> 编辑器行为 -> 右大括号自动格式化(取消选中此项)。

enter image description here

在此处输入图片说明

回答by Csaba Toth

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:

这是 VS 2013 测试版中无法完全关闭的错误,请参阅 FuleSnabel 提交的问题:http://connect.microsoft.com/VisualStudio/feedback/details/797716/turning-off-auto-formatting-for-vs2013 -c-only-seems-to-partial-disable-auto-formatting。一些可能的解决方法:

  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 .vssettingsXML 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.
  1. 如果您只是查看一些具有不同/奇怪风格的项目:如果发生了不需要的自动格式化,那么您可以执行一个撤消步骤,这应该仅撤消操作的自动格式化部分,而不是您的贡献。幸运的是,这两个(或有时更多的自动格式化步骤)并没有组合成一个命令,这可能正是出于这个原因:您可以返回并覆盖它。如果这种情况一直发生,那就很烦人了。您可以配置行为以匹配您的风格,但您说您的项目具有不同的代码风格。
  2. 工具/导入和导出设置... - 您可以导出某个项目的特定设置,然后再导入。这将保存.vssettingsXML 格式文件。如果它只是一种特定的文件类型,那么它可能只有几千字节长。不幸的是,这需要手动步骤。最好的情况是,这些设置是否可以从解决方案配置文件甚至项目配置文件中被覆盖,也可以成为其中的一部分。
  3. 请注意,如果您真的在同时打开 Visual Studio 的项目中并行工作,那么第二点是有问题的。在这种情况下,我认为最后关闭的 VS 实例的设置将最终保存。

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.

为解决方案保存不同的自动格式可能是下一个版本的功能请求(当然不会在 VS 2013 中实现)。我通常遇到的是制表符/空格缩进行为的差异,这是项目样式中最常见的差异。缩进也可以为大多数文件类型单独配置,但就像你的情况一样,项目可能会有所不同,然后就会变得很烦人。

回答by Eugene

Go to:

去:

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

工具->选项->文本编辑器->C/C++->格式->间距

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

然后取消选择或选择与您正在编写的代码类型相关的框。

回答by samraat55

To turn off automatic brace completion, go to:

要关闭自动大括号完成,请转到:

Tools > Options > Text Editor > All Languages > General > Automatic brace completion

工具 > 选项 > 文本编辑器 > 所有语言 > 常规 > 自动大括号完成

...then uncheck "Automatic brace completion".

...然后取消选中“自动大括号完成”。