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

No Such Dev
1 min readJan 27, 2020

--

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!

--

--

No Such Dev
No Such Dev

Written by No Such Dev

Software Engineer | Indie Game Developer | Founder of No Such Studio. Follow me to learn how to make video games with Unity. http://www.nosuchstudio.com

Responses (3)