Place curly braces on a New Line in VS Code in JS and TS

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# Place curly braces on a New Line in VS Code for JavaScript and TypeScript

To place curly braces on a new line in Visual Studio Code:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type placeOpenBraceOnNew into the search field.

  2. Tick the four checkboxes.

place curly braces on new line

The Place Open Brace on New Line for Control Blocks setting is available for JavaScript and TypeScript.

When enabled, the setting puts open braces onto a new line for control blocks.

control block open brace on new line

The Place Open Brace On New Line For Functions setting is also available for JavaScript and TypeScript.

When enabled, the setting puts open braces onto a new line for functions.

open brace new line functions

Note that if you use Prettier, you can't configure VS Code to place curly braces on a new line.

This is because Prettier is an opinionated code formatter and doesn't support this.

# Place curly braces on a New Line in VS Code in settings.json

You can also enable the setting in a settings.json file:

  1. In the root directory of your project, create a .vscode folder.
  2. Create a settings.json file in the .vscode folder.

Add the following code to the .vscode/settings.json file.

.vscode/settings.json
{ "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true, "javascript.format.placeOpenBraceOnNewLineForFunctions": true, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, "typescript.format.placeOpenBraceOnNewLineForFunctions": true, }

open brace new line functions

Make sure the .vscode/settings.json file is located in the root directory of your project.

When you set the properties in .vscode/settings.json, they are local to your project.

You can also set the properties globally.

# Place curly braces on a New Line in VS Code using your global settings.json file

If you need to enable the setting in your global settings.json file:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Add the following properties to the object in the settings.json file.
settings.json
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true, "javascript.format.placeOpenBraceOnNewLineForFunctions": true, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, "typescript.format.placeOpenBraceOnNewLineForFunctions": true,

Make sure the properties are wrapped in an object if your settings.json file is empty.

settings.json
{ "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true, "javascript.format.placeOpenBraceOnNewLineForFunctions": true, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, "typescript.format.placeOpenBraceOnNewLineForFunctions": true, }

When the properties are set in your user's setting.json file, they take effect for all projects as long as you are logged in with the specific user.

I've also written an article on how to enable Font Ligatures in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.