Last updated: Apr 6, 2024
Reading time·3 min
To place curly braces on a new line in Visual Studio Code:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
Type placeOpenBraceOnNew into the search field.
Tick the four checkboxes.
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.
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.
This is because Prettier is an opinionated code formatter and doesn't support this.
You can also enable the setting in a settings.json file:
settings.json
file in the .vscode
folder.Add the following code to the .vscode/settings.json
file.
{ "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true, "javascript.format.placeOpenBraceOnNewLineForFunctions": true, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true, "typescript.format.placeOpenBraceOnNewLineForFunctions": true, }
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.
If you need to enable the setting in your global settings.json
file:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json
.
Click on Preferences: Open User Settings (JSON)
settings.json
file."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.
{ "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.
You can learn more about the related topics by checking out the following tutorials: