如何设置 VSCode 将花括号放在新行上? [英] How do I set up VSCode to put curly braces on a new line?

查看:176
本文介绍了如何设置 VSCode 将花括号放在新行上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我输入以下代码并对其进行格式化.

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

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

如果这是C#代码,格式如下:

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

if (condition)
{
    // Hello!
}

如果是 JavaScript,VSCode 的格式如下:

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?

推荐答案

请按照以下步骤使 Visual Studio Code 格式在 Java Script 格式的新行上打开花括号 和 Type Script.

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

Visual Studio Code (v1.20.0)

  1. 转到文件首选项设置
  2. 用户设置"(右侧窗格中)中添加以下几行

  1. Go to FilePreferencesSettings
  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,

  • 保存用户设置",大功告成!

    这篇关于如何设置 VSCode 将花括号放在新行上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆