I want VS Code to put curly braces on a new line in C# and C++
How it works now
How it should look
Tried C# FixFormat extension, but it works only after I push CTRL+K+F but I want VS Code to make curly braces on new lines while I'm coding, without additional steps like hotkeys and such
Now that C#FixFormat has been removed, try putting an omnisharp.json
file in the root of your project with the following.
{
"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
}
}
In my case, I was using the C# extension by Microsoft (3.5 stars). By default, this extension uses its default C# formatter. Disable the formatting option as shown below, and you won't get any for formatting, including the annoying NewLinesForBracesInMethods
. Alternatively you can try to tweak the C# extension formatter. More info here.
So I replaced it with the C# FixFormat (5 stars) extension. This seems to work straight of the box for me.
But then I realised, I wasn't getting autocomplete, so I reinstalled the C# extension by microsoft, and kept the FixFormat extension. And it works great, no new lines for braces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With