Keep still, catch, on the same line as the closing bracket in Visual Studio 2015?

I managed to get Visual Studio to hold the open bracket on the same line (the settings for this are under Formatting -> New Lines ; the settings I'm looking for, if they exist, are not in this option area):

 void foo() { bar(); } 

but I cannot figure out how to save the else and catch blocks on the same line as the end bracket of the previous statement.

To clarify, this is what Visual Studio automatically formats:

 if (foo) { return 1; } else { return 2; } 

and this is what I want:

 if (foo) { return 1; } else { return 2; } 
+5
source share
1 answer

Go to Tool Option , then General Text editor C++ Formatting New lines .

Select the following settings:

  • Opening bracket position for control unit: switch for the same line
  • Keyword Position: Uncheck the else character on a new line.

A preview of this last setting will display

 if (a < b) { } else { } 

but this does not take into account the first option.

If you enter the if / else statement, select a region and ask the editor to reformat. The statement will look like:

 if (test) { } else { } 

I could try it successfully at Visual Studio 2015. I tested it in a foreign language, so the English wording of the above options may be slightly different, but close enough to be found.

+8
source

All Articles