Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up VSCode to put curly braces on a new line?

Let's say I type in the following code and format it.

if (condition) { /* Hello! */ } 

If this is C# code, it is formatted like this:

if (condition) {     // Hello! } 

If it is JavaScript, VSCode formats it like this:

if (condition) {     // Hello! } 

So how can I use the first formatting style (curly braces on new lines) for all languages? I can't find a setting or something similar. Suggestions?

like image 509
M. Fatih Avatar asked Oct 02 '15 05:10

M. Fatih


People also ask

How do I see the lines that connect braces in Visual Studio?

Go to Tools->Options->Productivity Power Tools->Other Extensions and there is an option group called Structure visualizer options. In there is a checkbox for Show code structure in editor. Turn this off, and job done!

Should curly braces be on their own line C++?

Braces are totally not worth separate line. The thing is that braces are not important.


2 Answers

Follow the steps below to make Visual Studio Code format opening curly braces on a new line for Java Script and Type Script.

In Visual Studio Code (v1.20.0)

  1. Go to File\Preferences\Settings
  2. Add the following lines in 'User Settings' (in the right side pane)

    "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,  "javascript.format.placeOpenBraceOnNewLineForFunctions": true,  "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, "typescript.format.placeOpenBraceOnNewLineForFunctions": true, 
  3. Save 'User Settings' and you are done!

like image 97
Advait Baxi Avatar answered Oct 08 '22 08:10

Advait Baxi


Go to File\Preferences\Settings and search for 'brace'.

Enable the settings illustrated below.

This allows me to auto-format code with curly braces on the following line for function definitions and control blocks.

File\Preferences\Settings

Tested with Visual Studio Code 1.30.2

like image 42
Charley Ramm Avatar answered Oct 08 '22 08:10

Charley Ramm