我希望VS Code在C#和C ++中将花括号放在新行上
现在的工作方式:
应该这样看:
尝试了C# FixFormat扩展,但只有在按下CTRL + K + F后才能运行,但我想在编码时VS Code自动将花括号放在新行上,而不需要其他步骤,如热键等。
现在的工作方式:
![How it works now](https://media.giphy.com/media/h40eFwZ7GnB4WVrbLg/giphy.gif)
![How it should look](https://media.giphy.com/media/jsxsvZG5mYCHXoilvo/giphy.gif)
由于 C#FixFormat 已被移除,请尝试将以下内容放入项目根目录下的 omnisharp.json
文件中。
{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
"NewLinesForBracesInAccessors": false,
"NewLineForElse": false,
"NewLineForCatch": false,
"NewLineForFinally": false
}
}
NewLinesForBracesInMethods
。或者您可以尝试调整C#扩展程序的格式化程序。更多信息在此处。$HOME/.omnisharp
(如果不存在该目录,则需要创建)omnisharp.json
alt + shift + f
格式化代码{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
"NewLinesForBracesInAccessors": false,
"NewLineForElse": false,
"NewLineForCatch": false,
"NewLineForFinally": false
}
}
omnisharp.json
文件。要么这样,要么使用.editorConfig
文件。 https://github.com/OmniSharp/omnisharp-vscode/issues/5446#issuecomment-1308655891 - fenix.shadow