简体   繁体   English

函数参数的 Visual Studio 缩进

[英]Visual studio indentaion of function arguments

VS v010 indent the following C++ code as: VS v010 将以下 C++ 代码缩进为:

 if (Foo(arg1,
     arg2))
 {
 }

Is there a way to change VS formatting rules to indent the code as below:有没有办法更改 VS 格式规则以缩进代码,如下所示:

 if (Foo(arg1,
         arg2))
 {
 }

Thanks谢谢

Update更新

Why are those minuses?为什么会有这些缺点? Don't you think guys code style is important or there'is some other reason?你不认为代码风格很重要还是有其他原因?

No, there's no way "out of the box" to force Visual Studio to indent code that way.不,没有办法“开箱即用”来强制 Visual Studio 以这种方式缩进代码。 It's always going to indent wrapped function parameters with only a single tab.它总是只用一个选项卡缩进包装的函数参数。

It turns out that such a style is in accordance with Microsoft's general coding guidelines, and probably why they've written it that way.事实证明,这种风格符合 Microsoft 的一般编码指南,并且可能是他们这样编写的原因。 I don't much care for it either, though, also preferring your style.不过,我也不太在意,也更喜欢你的风格。

But it turns out that you only have to manually indent the first wrapped parameter.但事实证明,您只需手动缩进第一个包装参数。 Subsequently, when you press Enter , Visual Studio will automatically start the next line underneath your first carefully lined up parameter.随后,当您按Enter 时,Visual Studio 将自动在您仔细排列的第一个参数下方开始下一行。

Also remember that (if you've already written the method definitions), you can select multiple lines at a time and use the Tab key to line them all up.还请记住(如果您已经编写了方法定义),您可以一次选择多行并使用Tab键将它们全部对齐。 You don't have to do one at a time.你不必一次做一个。

In general, there are unfortunately extremely limited code formatting options available for C/C++ code in Visual Studio.通常,遗憾的是,Visual Studio 中可用于 C/C++ 代码的代码格式选项极其有限。 The C# programmers get a lot more goodies. C# 程序员获得了更多好东西。 You might be able to invest in an add-in or extension like Visual Assist X that gets you more features in the IDE.您也许可以投资于Visual Assist X 之类的加载项或扩展程序,以在 IDE 中为您提供更多功能。

Try using a tool called Artistic Style (short for astyle ).尝试使用一种名为Artistic Styleastyle 的缩写)的工具。 It can customize almost all your required code format.它可以自定义几乎所有您需要的代码格式。 Regards to your indentation format, check its document on max‑instatement‑indent .关于您的缩进格式,请查看max-instatement-indent上的文档。 Furthermore, this tool can be easily integrated into Visual Studio.此外,该工具可以轻松集成到 Visual Studio 中。 Net (check THIS for a quick setup). Net(检查 这个以进行快速设置)。

I think this is a duplicate of Automatic indentation of arguments list on multiple lines in Visual Studio In which I provided an answer for VS2017.我认为这是Visual Studio 中多行参数列表自动缩进的副本,其中我为 VS2017 提供了答案

Under tools->options->Text editor->C/C++->Formatting->Indentation->"Within parentheses, align new lines when I type them" Choose the option "Align contents to opening parentheses.在工具->选项->文本编辑器->C/C++->格式->缩进->“在括号内,在我输入时对齐新行”选择选项“将内容与左括号对齐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM