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++的自动格式化。我个人对自动格式的看法是,它最终对开发者有害,但我必须接受并不是所有人都同意。让我烦恼的是我似乎不能完全禁用自动格式化。我检查了工具栏下的所有复选框——>文本编辑器——>C/ c++ ->格式——>,但当我输入:
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
我不想改变间距设置,因为
- I work in multiple projects with different code standards
- 我在不同代码标准的多个项目中工作
- 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.
我只是想VS不自动修改我的代码。
PS. I am not against that VS can format code but I want to invoke that manually
我并不反对VS可以格式化代码,但我想手动调用它
7 个解决方案
#1
36
You can turn off automatic C / C++ /C# code formatting by going to the Options dialog from the Tools menu, selecting the Text Editor → C / C++ / C# → Formatting → General 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.
你可以关掉自动C / c++ / c#代码格式化工具菜单中的选项对话框,选择文本编辑器→C / c++ / c#→格式→一般页面,并取消勾选所有的盒子。当所有的自动格式设置都被关闭时,您仍然可以手动设置格式。
#2
8
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.
我知道这并不是你要找的答案,但是你可以保护人空缺f()格式如果你去工具>选项>文本编辑器> C / c++ >格式>间距和间距下函数parantheses您检查选项之间插入空间函数名和参数列表的开始括号。
#3
6
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.
事实证明,这是由整个番茄软件的插件“视觉辅助X”中的一个选项引起的。
In my case this problem could be solved by going to “Visual Assist Options”-->”Corrections” and unchecking the Checkbox “Format after paste”.
在我的例子中,这个问题可以通过“Visual Assist Options”——>“correct”和“Format after paste”取消复选框来解决。
#4
3
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 /turn -off-auto-formatting-for vs2013-c-似乎可以部分禁用的自动格式。一些可能的解决方法:
- 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.
- 如果您只是查看一些具有不同/奇怪样式的项目:如果发生不需要的自动格式化,那么您可以执行一个撤消步骤,这应该只撤消操作的自动格式化部分,而不是您的贡献。幸运的是,这两个(有时是更多的自动格式化步骤)并没有合并到一个命令中,可能正是因为这个原因:您可以返回并覆盖它。虽然这种情况经常发生,但这很烦人。您可以配置行为以匹配您的样式,但是您说您有具有不同代码样式的项目。
- 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. - 工具/进出口设置…-您可以导出某个项目的特定设置,然后再导入它。这将保存.vssettings XML格式文件。如果它只是一个特定的文件类型,那么它可能只有几千字节长。不幸的是,这需要手工步骤。最好的情况是,如果这些设置可以从解决方案配置文件中重写,甚至项目配置文件也可以是其中的一部分。
- 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.
- 注意,如果您在项目中同时使用开放的Visual Studios进行并行工作,那么第二点就有问题了。在这种情况下,设置将最终保存我认为最后一个关闭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)。我通常遇到的是制表符/空格缩进行为的差异,这是项目风格中最常见的差异。缩进也可以为大多数文件类型单独配置,但与您的情况一样,项目可能会有所不同,然后就会变得令人讨厌。
#5
3
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 ->选项->环境->编辑器->编辑器行为->关闭括号自动格式化(取消勾选)。
#6
1
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.
然后取消选择或选择与您正在编写的代码类型相关的框。
#7
1
To turn off automatic brace completion, go to:
要关闭自动支撑完成,请转到:
Tools > Options > Text Editor > All Languages > General > Automatic brace completion
工具>选项>文本编辑器>所有语言>通用>自动支撑完成
...then uncheck "Automatic brace completion".
…然后取消检查“自动支撑完成”。
#1
36
You can turn off automatic C / C++ /C# code formatting by going to the Options dialog from the Tools menu, selecting the Text Editor → C / C++ / C# → Formatting → General 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.
你可以关掉自动C / c++ / c#代码格式化工具菜单中的选项对话框,选择文本编辑器→C / c++ / c#→格式→一般页面,并取消勾选所有的盒子。当所有的自动格式设置都被关闭时,您仍然可以手动设置格式。
#2
8
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.
我知道这并不是你要找的答案,但是你可以保护人空缺f()格式如果你去工具>选项>文本编辑器> C / c++ >格式>间距和间距下函数parantheses您检查选项之间插入空间函数名和参数列表的开始括号。
#3
6
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.
事实证明,这是由整个番茄软件的插件“视觉辅助X”中的一个选项引起的。
In my case this problem could be solved by going to “Visual Assist Options”-->”Corrections” and unchecking the Checkbox “Format after paste”.
在我的例子中,这个问题可以通过“Visual Assist Options”——>“correct”和“Format after paste”取消复选框来解决。
#4
3
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 /turn -off-auto-formatting-for vs2013-c-似乎可以部分禁用的自动格式。一些可能的解决方法:
- 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.
- 如果您只是查看一些具有不同/奇怪样式的项目:如果发生不需要的自动格式化,那么您可以执行一个撤消步骤,这应该只撤消操作的自动格式化部分,而不是您的贡献。幸运的是,这两个(有时是更多的自动格式化步骤)并没有合并到一个命令中,可能正是因为这个原因:您可以返回并覆盖它。虽然这种情况经常发生,但这很烦人。您可以配置行为以匹配您的样式,但是您说您有具有不同代码样式的项目。
- 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. - 工具/进出口设置…-您可以导出某个项目的特定设置,然后再导入它。这将保存.vssettings XML格式文件。如果它只是一个特定的文件类型,那么它可能只有几千字节长。不幸的是,这需要手工步骤。最好的情况是,如果这些设置可以从解决方案配置文件中重写,甚至项目配置文件也可以是其中的一部分。
- 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.
- 注意,如果您在项目中同时使用开放的Visual Studios进行并行工作,那么第二点就有问题了。在这种情况下,设置将最终保存我认为最后一个关闭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)。我通常遇到的是制表符/空格缩进行为的差异,这是项目风格中最常见的差异。缩进也可以为大多数文件类型单独配置,但与您的情况一样,项目可能会有所不同,然后就会变得令人讨厌。
#5
3
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 ->选项->环境->编辑器->编辑器行为->关闭括号自动格式化(取消勾选)。
#6
1
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.
然后取消选择或选择与您正在编写的代码类型相关的框。
#7
1
To turn off automatic brace completion, go to:
要关闭自动支撑完成,请转到:
Tools > Options > Text Editor > All Languages > General > Automatic brace completion
工具>选项>文本编辑器>所有语言>通用>自动支撑完成
...then uncheck "Automatic brace completion".
…然后取消检查“自动支撑完成”。