VSCode Unity Godot C# 大括号不换行设置方法

默认格式化方法

void Start() 
{
}

C# 大括号不换行

void Start() {
}

 

需要安装

  EditorConfig for VS Code  插件

在设置中

  禁用 Use Omnisharp

  启用 Enable Editor Config Support

 

在项目根目录创建 .editorconfig 配置文件,

或者在user目录下创建 .editorconfig 配置文件 实现全局生效。
内容如下

# 参考自 https://learn.microsoft.com/zh-cn/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
root = true
# 所有文件
[*]
charset = utf-8
# CS文件
[*.cs]
indent_style = tab
indent_size = 4
tab_width = 4
 
# if (...) {
#     ...
# }
csharp_new_line_before_open_brace = none
# if (...) {
#     ...
# } else {
#     ...
# }
csharp_new_line_before_else = false
# try {
#     ...
# } catch (Exception e) {
#     ...
# }
csharp_new_line_before_catch = false
# try {
#     ...
# } catch (Exception e) {
#     ...
# } finally {
#     ...
# }
csharp_new_line_before_finally = false
# 错误提示,如果不正常可以删掉
dotnet_diagnostic.IDE0055.severity = error

 

保存后重启,效果如下

 

引用自:

如何让我的 Omnisharp 格式化程序在 C# 开发工具包中工作? ·期刊 #6026 ·dotnet/vscode-csharp ·GitHub的

C# 格式设置选项 - .NET | Microsoft Learn

Code style formatting rule IDE0055 - .NET | Microsoft Learn

posted @ 2023-12-20 22:47  letleon  阅读(336)  评论(0编辑  收藏  举报