VScode格式化程序,在同一行中保持开放括号(PHP)

时间:2019-03-27 12:01:10

标签: php visual-studio-code vscode-settings

我已启用“ editor.formatOnSave”设置,但是在代码为formate的php文件中,所有大括号将换行。我只希望他们留在同一行前

function test{

}

不是

function test
{

}

我整天都在寻找解决方案,但找不到任何东西

3 个答案:

答案 0 :(得分:11)

如果您想要这样格式化PHP代码

function test {

}

然后使用intelephense进行以下设置。

  "intelephense.format.braces": "k&r"

答案 1 :(得分:2)

VScode 的新版本已经包含此功能。

您只需在 VScode 设置中搜索“intelephense”,然后查找名为“Braces”的设置。

VScode Intelephense braces setting

答案 2 :(得分:1)

intelephence中有默认的格式化程序,它没有很多自定义选项。您可以在特定于php语言的设置中将其禁用:

~/.config/Code - OSS/User/settings.json:
----------
...
"[php]": {
    // "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
    "editor.defaultFormatter": "kokororin.vscode-phpfmt"
},
...

然后,您可以使用其他一些支持自定义的格式化程序,例如phpfmt。这是我的设置:

"phpfmt.exclude": [
    "AllmanStyleBraces"
],
"phpfmt.smart_linebreak_after_curly": true,
"phpfmt.psr2": false,
"phpfmt.detect_indent": true
相关问题