dimba
dimba

Reputation: 27571

Visual Studio indentation of function arguments

Visual Studio 2010 indents the following C++ code as:

 if (Foo(arg1,
     arg2))
 {
 }

Is there a way to change Visual Studio formatting rules to indent the code as below:

 if (Foo(arg1,
         arg2))
 {
 }

Upvotes: 10

Views: 4556

Answers (3)

turoni
turoni

Reputation: 1435

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 Visual Studio 2017.

Under menu ToolsOptionsText editorC/C++FormattingIndentation"Within parentheses, align new lines when I type them".

Choose the option "Align contents to opening parentheses.

Upvotes: 4

james
james

Reputation: 1155

Try using a tool called Artistic Style (short for astyle). It can customize almost all your required code format. Regards to your indentation format, check its document on max‑instatement‑indent.

Furthermore, this tool can be easily integrated into Visual Studio .NET (check this for a quick setup).

Upvotes: 2

Cody Gray
Cody Gray

Reputation: 244672

No, there's no way "out of the box" to force Visual Studio to indent code that way. 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. 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.

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. 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. The C# programmers get a lot more goodies. You might be able to invest in an add-in or extension like Visual Assist X that gets you more features in the IDE.

Upvotes: 11

Related Questions