How to change code formatting in Visual Studio Cod

2019-08-09 22:46发布

Hi I'm using VS Code for TypeScript and JavaScript. Standart autoformat create code like this

if(ind){
 // code
}

but I don't like this :), how to set autoformat as

if(ind)
{
    // code
}

2条回答
forever°为你锁心
2楼-- · 2019-08-09 23:19

This is currently not possible with VsCode, but there is an issue tracking the problem and here's the actual code fix.

Keep in mind that this is from the development branch, so the behavior and settings may change, but I believe the settings you will want are:

javascript.format.placeOpenBraceOnNewLineForControlBlocks and/or javascript.format.placeOpenBraceOnNewLineForFunctions

This feature should make it into an official release shortly, but if you want the try out bleeding edge features you can always build VsCode from the source.

查看更多
Rolldiameter
3楼-- · 2019-08-09 23:19

for TypeScript in settings.json

// Place your settings in this file to overwrite default and user settings.
{
    "typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
    "typescript.format.placeOpenBraceOnNewLineForFunctions": true
}

and autoformat!

查看更多
登录 后发表回答