Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode format curly brackets on the same line c#

When using the Format Document command I'd like to change how the code formats. I'm completely new to VSCode and I'm still having trouble navigating the settings, so easy to understand replies would be very helpful. Currently the code is formatting like this:

void start () { //Do stuff here } 

I want it to look like:

void start () { //Do stuff here } 
like image 559
Gordoxgrey Avatar asked Mar 06 '18 16:03

Gordoxgrey


People also ask

Where do I put my curly brackets in C?

In programming, curly braces (the { and } characters) are used in a variety of ways. In C/C++, they are used to signify the start and end of a series of statements. In the following expression, everything between the { and } are executed if the variable mouseDOWNinText is true. See event loop.


1 Answers

I have found this simple solution for VScode !

Just create a file called omnisharp.json at the root of your project and paste the following JSON :

{     "FormattingOptions": {         "NewLinesForBracesInLambdaExpressionBody": false,         "NewLinesForBracesInAnonymousMethods": false,         "NewLinesForBracesInAnonymousTypes": false,         "NewLinesForBracesInControlBlocks": false,         "NewLinesForBracesInTypes": false,         "NewLinesForBracesInMethods": false,         "NewLinesForBracesInProperties": false,         "NewLinesForBracesInObjectCollectionArrayInitializers": false,         "NewLinesForBracesInAccessors": false,         "NewLineForElse": false,         "NewLineForCatch": false,         "NewLineForFinally": false     } } 

I found the solution here: https://medium.com/@wearetherock/visual-studio-code-c-put-the-opening-brace-on-the-same-line-as-the-statement-a98c552a544b

like image 114
Pini Cheyni Avatar answered Sep 26 '22 13:09

Pini Cheyni