Formatting a switch statement

Let's say that I have a cursor position to the right of the curly brace in the right face, for example:

enter image description here

Now, if I press enter, I expect it to automatically align the cursor with two tabs, like the break statement. But what is it:

enter image description here

He adds a funny five tabs! Knowing that Visual Studio has a metric ton of settings, I go to Tools::Settings::Text Editor::C/C++::Formatting::Indentation and see the following window:

enter image description here

But changing the highlighted options in any combination does not actually affect the indentation at all! None of the other options seem to apply to switch statements, so I don't know what to do. How to do this without indenting 5 spaces without disabling auto formatting?

And I could add that it not only places 5 tabs when I press the enter button at the end of the curly bracket, but when an event with automatic formatting occurs. Therefore, when I add a semicolon at the end of the line, it places 5 tabs, even if I took them out earlier.

+7
c ++ indentation visual-studio-2013
source share
3 answers

I entered VS2013 and created a new project and just tried to make a really simple switch , but it is formatted correctly for me, even with curly braces. Can you post this code?

The only thing I can think of is maybe adjusting how the curly braces are set up, but I don't know why this would affect it. (I also don’t think that there are even settings for C ++ for this ...) Besides that, although you can try not to use the bindings at all, since you are inside the case , you do not need them technically.

In addition, something could happen during installation. Therefore, reinstallation is also an option.

EDIT:
Alternatively, you can just go with it and finish the code, and then, when done, just select the lines and un-indent ([SHIFT] + [TAB]) back to the right place.

+1
source share

This is probably a little late for you, but if someone else finds this problem: it seems to be a Visual Studio bug, you are probably using the newly installed version of VS2K13 called REL.

Downloading Update 4 at http://www.microsoft.com/en-us/download/details.aspx?id=44921 helped in my case.

+3
source share

Curly braces ( { and } ) discard the automatic indenter and are missing up to one tab behind the brace.

The brackets there are not illegal in the switch statement, but they usually do not help you. If you do not need this to define a variable declaration, just remove the curly braces. You will get the same code stream and you will not confuse the auto-indicator.

EDIT Think about it, you can solve it by simply moving the bracket to a new line. This is not necessarily terrible - it emphasizes that you are using a bracket.

 case SDLK_g: { // etc break; } 
+2
source share

All Articles