Braces on new lines in Visual Studio Code

Here there be dragons: Some people prefer their braces on the same line, some prefer them on the next line. If you're in the latter camp then the default in Visual Studio Code will annoy you - it's easy enough to change though.

Start off by opening Visual Studio Code and then click on the small "cog" icon at the bottom left of the screen:

The cog at the bottom left of the screen opens the Visual Studio Code user settings editor

This will bring up the settings editor:

The editor for Visual Studio Code user settings

Once this is open it's a simple matter to search for the relevant settings (for me, anyway!), which are:

  • javascript.format.placeOpenBraceOnNewLineForControlBlocks
  • javascript.format.placeOpenBraceOnNewLineForFunctions

You can search on 'placeOpenBraceOnNewLine' which will return both of these, along with their TypeScript counterparts, which can then be added to the "User Settings" on the right-hand side. If you're dealing with one project where you have to match (or want to enforce!) conventions, you can set these values in the "Workspace Settings" tab to have them only apply to that workspace.

For User Settings, you'll end up with an editor that looks something like this (assuming you haven't got any other setting customisations):

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
    "javascript.format.placeOpenBraceOnNewLineForFunctions": true,
}

About Rob

I've been interested in computing since the day my Dad purchased his first business PC (an Amstrad PC 1640 for anyone interested) which introduced me to MS-DOS batch programming and BASIC.

My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.

No Comments

Add a Comment