Reputation: 238
I've managed to get Visual Studio to keep the opening bracket on the same line like this (the settings for this are under Formatting -> New Lines
; the settings I am looking for, if they exist, are not in this area of options):
void foo() {
bar();
}
but I can't figure out how to keep else and catch blocks on the same line as the ending bracket of the previous statement.
To clarify, this is what Visual Studio auto-formats to:
if (foo) {
return 1;
}
else {
return 2;
}
and this is what I want:
if (foo) {
return 1;
} else {
return 2;
}
Upvotes: 10
Views: 4670
Reputation: 73465
Go to Tool
->Option
then General
->Text editor
->C++
-> Formatting
-> New lines
.
Choose the following settings:
The preview for this last setting will display
if (a < b)
{
} else
{
}
but this doesn't take into account the first option.
If you type an if/else statement, select the region, and ask the editor to reformat. The statement will appear as:
if (test) {
} else {
}
I could try this successfully on Visual Studio 2015. I tested it with a foreign language, so the english wording of above mentioned options might be slightly different, but close enough for being found.
Upvotes: 16