Stop visual studio 2013 from repositioning braces on new line?

When I press enter, it reposition the braces. How can I stop that? I want VS to keep automatically adding a closing brace after I type an opening brace, but I don't want it to move the brace on enter. How can I do that?

Upvotes: 7

Views: 5719

Answers (2)

StarPilot
StarPilot

Reputation: 2272

In Visual Studio 2013, you can change that option by doing the following:

  1. Go to menu and select: "Tools|Options"
  2. Select node "Text Editor"
  3. Select node "C#"
  4. Select node "Formatting"
  5. Select node "New Lines"
  6. Uncheck "Place open brace on new line for... " whatever you don't want the opening brace to be moved down to the next line for.
  7. Select "OK button"

This is the automatic behavior styling. This means if you copy/paste, or complete a block, if your "format on paste" option is option, VS will restyle the pasted block. If your "format block on completion" option is on, it will restyle the block (putting the opening brace where the style demands it).

From your comments, it seems you should be asking "How do I turn off style enforcement?" or "How do I only enforce brace style on if blocks?"

You could go into "Tools|Options|Text Editor|C#|Formatting|General" and uncheck the Automatically format options to prevent the enforced styling whenever you paste, complete a block by typing }, or ;, but it won't stop all the automatic restyling in the Visual Studio editor when editing C# file types.

Upvotes: 11

Dave Kidder
Dave Kidder

Reputation: 1838

There isn't a setting that I am aware of to leave it on the line that you typed it (since most groups establish coding style standards that would state to put the opening brace should always be on the same line or always on the new line).

You can get VS to "forget" what it is supposed to do with a brace by moving the cursor outside of the brace block. So if you leave the Options >> Formatting setting checked (so it would normally put the brace on the next line) you can get the opening brace to stay on the same line by hitting RIGHT ARROW, LEFT ARROW, ENTER (i.e. move the cursor past the end brace, then move it back between the braces, then enter a new line).

Not what you wanted, but that's the best I can think of.

Upvotes: 3

Related Questions