Auto Formatting Curly Braces on the Same Line in C# in VSCode

Image for post
Image for post

I’m using Unity on Ubuntu. VSCode is by far the best editor for C# and Unity. Auto formatting is one of the very useful features of VSCode. To have VSCode format your code, select parts of your code (or Ctrl + A to select all), then pressing Ctrl + K followed by Ctrl + F . By default it formats the braces on a new line like below.

Many lines are wasted just to show a single curly brace. I like the more compact formatting of putting the opening braces on the same line:

It makes the code more compact without any downsides IMO. It is however a matter of personal preference which one you use. I’m not here to convince you to do this or not, but just do it!

To get VSCode to do the compact formatting, simply create a file named omnisharp.json in the root of your Unity project (beside your Assets folder) with the following content and then restart VSCode.

Happy Coding!

Written by

Software Engineer | Indie Game Developer | Founder of No Such Studio. Follow me to learn how to make video games with Unity.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store