29

Seriously, I don't know what to google. Here's the thing, I like this Java-like code writing:

if (condition == true) { doSomeStuff(); } 

But VisualStudio "helps" me with its own "style", which I don't like and I am unable to change (after rather big time of desperate checking all settings :/)

if (condition == true) { DoStuff(); } 

I obviously want the "{" char to be in same line where condition is ...

I am using MS Visual Studio 2010 professional.

3
  • 1
    Does the 2008 way work? stackoverflow.com/questions/39561/… Commented May 15, 2010 at 21:58
  • 1
    Why do you want to do it the wrong way? ;) Commented May 15, 2010 at 22:17
  • Those are called curly braces or brackets. Commented May 15, 2010 at 22:18

5 Answers 5

46

Go to Tools > Options > Text Editor > [Language, i.e.: C#] > Code Style > Formatting > New Lines

This is where you can set your new line options for braces.

See the image below for more clarification.

menu

Sign up to request clarification or add additional context in comments.

4 Comments

I always forget this.
For Visual Studio Code go File -> Preferences -> Settings and under Extensions choose the language you want to change properties. Search for Clang_format_fallback Style (e.g.: for C++ C_Cpp: Clang_format_fallback Style) and change the value from Visual Studio to Google
In Visual Studio in 2018 (Community version on a Mac, 8.0.5): Preferences -> Source Code -> Code Formatting -> [Language (e.g. C#)] -> Change the Tab to C# Format -> Click "Edit". Then change the category to "New Lines" and you get all the options, which you may want to turn off.
Thank goodness. What a terrible way to code.
7

Tools -> Options ...

alt text http://img6.imageshack.us/img6/158/capturejo.png

Comments

6

Text Editor > C# > Formatting > New Lines > New line options for braces

  • Uncheck Place open brace on new line for control blocks.
  • Probably want to uncheck put else on newline as well.

Comments

1

This is for Visual Stuio 2008, so I'm not sure that it's exactly the same in VS 2010:

Go to the Tools menu and open Options. Make sure that the Show all settings checkbox is checked. Open the Text Editor node and then the node for the language you want to change the setting for. Open the Formatting node and select the New Lines node. Here you can change when new lines are added to the code.

After installing Visual Studio I go in there and uncheck every option in the New Lines section.

Comments

0

Worth knowing is that Steve Horn's (and others) answer works even for other languages as they seem to appear to not have the same settings-layout. I did the changes as described in his post and it worked for my C++ projects as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.