vscode C# 大括号不换行

标 签:

我个人不喜欢右大括号换行,不习惯,看起来不舒服

我用vscode 开发 c# 时,右大括号换行,找了很久,才找到一个方法,记录一下。

在项目根目录里创建一个文件,文件名为: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
  }
}

找了很久,在外网找到一个大神的配置,链接  https://www.strathweb.com/2017/01/c-code-formatting-settings-in-vs-code-and-omnisharp/

{
    "FormattingOptions": {
            "NewLine": "\n",
            "UseTabs": false,
            "TabSize": 4,
            "IndentationSize": 4,
            "SpacingAfterMethodDeclarationName": false,
            "SpaceWithinMethodDeclarationParenthesis": false,
            "SpaceBetweenEmptyMethodDeclarationParentheses": false,
            "SpaceAfterMethodCallName": false,
            "SpaceWithinMethodCallParentheses": false,
            "SpaceBetweenEmptyMethodCallParentheses": false,
            "SpaceAfterControlFlowStatementKeyword": true,
            "SpaceWithinExpressionParentheses": false,
            "SpaceWithinCastParentheses": false,
            "SpaceWithinOtherParentheses": false,
            "SpaceAfterCast": false,
            "SpacesIgnoreAroundVariableDeclaration": false,
            "SpaceBeforeOpenSquareBracket": false,
            "SpaceBetweenEmptySquareBrackets": false,
            "SpaceWithinSquareBrackets": false,
            "SpaceAfterColonInBaseTypeDeclaration": true,
            "SpaceAfterComma": true,
            "SpaceAfterDot": false,
            "SpaceAfterSemicolonsInForStatement": true,
            "SpaceBeforeColonInBaseTypeDeclaration": true,
            "SpaceBeforeComma": false,
            "SpaceBeforeDot": false,
            "SpaceBeforeSemicolonsInForStatement": false,
            "SpacingAroundBinaryOperator": "single",
            "IndentBraces": false,
            "IndentBlock": true,
            "IndentSwitchSection": true,
            "IndentSwitchCaseSection": true,
            "LabelPositioning": "oneLess",
            "WrappingPreserveSingleLine": true,
            "WrappingKeepStatementsOnSingleLine": true,
            "NewLinesForBracesInTypes": true,
            "NewLinesForBracesInMethods": true,
            "NewLinesForBracesInProperties": true,
            "NewLinesForBracesInAccessors": true,
            "NewLinesForBracesInAnonymousMethods": true,
            "NewLinesForBracesInControlBlocks": true,
            "NewLinesForBracesInAnonymousTypes": true,
            "NewLinesForBracesInObjectCollectionArrayInitializers": true
            "NewLinesForBracesInLambdaExpressionBody": true,
            "NewLineForElse": true,
            "NewLineForCatch": true,
            "NewLineForFinally": true,
            "NewLineForMembersInObjectInit": true,
            "NewLineForMembersInAnonymousTypes": true,
            "NewLineForClausesInQuery": true
    }
}


其它 / 评 论 (0) / 热度 (58℃) / 2020-11-11 / 阅读全文  / MaWei