Visual Studio - "{ }" settings
Asked Answered
P

5

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.

Pontine answered 15/5, 2010 at 21:51 Comment(3)
Does the 2008 way work? #40061Glycosuria
Why do you want to do it the wrong way? ;)Existentialism
Those are called curly braces or brackets.Turd
S
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

Spokeswoman answered 15/5, 2010 at 21:58 Comment(4)
I always forget this.Amphiprostyle
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 GoogleMadura
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.Wag
Thank goodness. What a terrible way to code.Polyptych
B
7

Tools -> Options ...

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

Buttons answered 15/5, 2010 at 22:5 Comment(0)
S
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.
Saipan answered 15/5, 2010 at 22:6 Comment(0)
G
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.

Goodwill answered 15/5, 2010 at 22:1 Comment(0)
H
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.

Hix answered 22/10, 2011 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.