代码之家  ›  专栏  ›  技术社区  ›  radbrawler

“{}”的Visual Studio代码格式

  •  125
  • radbrawler  · 技术社区  · 7 年前

    我在Ubuntu上。Visual Studio代码中的C++

    if (condition == true)
    {
      DoStuff();
    }
    

    if (condition == true) {
      DoStuff();
    }
    

    我该怎么做?

    我已经安装了 C/C++ 来自市场的扩展。

    6 回复  |  直到 4 年前
        1
  •  192
  •   Zam    5 年前

    基于@Chris Drew的回答

    1. 搜索C_Cpp。clang_format_fallbackStyle
    2. 单击编辑,复制到设置
    3. 从“Visual Studio”更改为 "{ BasedOnStyle: Google, IndentWidth: 4 }"

    例如

    • "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}"
    • 顺便说一句 ColumnLimit: 0

    更多细节:

    https://medium.com/@zamhuang/vscode-how-to-customize-c-s-coding-style-in-vscode-ad16d87e93bf

    台湾: https://medium.com/@zamhuang/vscode-%E5%A6%82%E4%BD%95%E5%9C%A8-vscode-%E4%B8%8A%E8%87%AA%E5%AE%9A%E7%BE%A9-c-%E7%9A%84-coding-style-c8eb199c57ce

        2
  •  57
  •   Chris Drew    5 年前
    • 文件 -&燃气轮机; 偏好 设置
    • C_Cpp.clang_format_fallbackStyle
        3
  •  15
  •   vk-code    6 年前

    我通常有自己的方式格式化几乎所有内容:)所以我更喜欢最灵活的方式来实现这一点。就c++格式而言,VS代码是迄今为止最灵活的编辑器,而且“简单”。

    这是获得自定义格式所需的操作。

    • 创建名为的文件。工作空间顶部文件夹下的叮当格式。
    • Clang format Style 了解各种可用选项。

    Standard: Cpp11
    BasedOnStyle: LLVM
    IndentWidth: 4
    ColumnLimit: 0
    AccessModifierOffset: -4
    NamespaceIndentation: All
    BreakBeforeBraces: Custom
    BraceWrapping:
      AfterEnum: true
      AfterStruct: true
      AfterClass: true
      SplitEmptyFunction: true
      AfterControlStatement: false
      AfterNamespace: false
      AfterFunction: true
      AfterUnion: true
      AfterExternBlock: false
      BeforeCatch: false
      BeforeElse: false
      SplitEmptyRecord: true
      SplitEmptyNamespace: true
    

    您特别感兴趣的格式是“AfterControlStatement:false”

        4
  •  0
  •   Adam Erickson    3 年前

    以MacOS为例,这是一种理想的配置方法 clang-format VS代码首先使用自制软件安装clang格式:

    brew install clang-format
    

    然后,使用它将完整样式设置导出到 ~/.clang-format :

    clang-format -style=google -dump-config > ~/.clang-format
    

    然后,在VS代码中执行以下操作:

    • Code/File -> Preferences -> Settings
    • "C_Cpp.clang_format_path": "/usr/local/opt/llvm/bin/clang-format"
    • "C_Cpp.clang_format_style": "Google"
    • "C_Cpp.clang_format_fallbackStyle": "Google"
    • "C_Cpp.intelliSenseEngine": "Tag Parser"

    clang-formatter 安装了Homebrew,它将自动从 ~/.clang格式

    最后一个参数, C_Cpp.intelliSenseEngine

        5
  •  -1
  •   Levi D Smith    5 年前

    安装C#FixFormat扩展

    • 查看(>);扩大

    如果它抱怨有多个格式化程序,那么按Configure按钮并选择C#FixFormat。

    可以通过转到File>返回到在新行上打开大括号;首选项>设置。然后向下滚动到Extensions,C#FixFormat configuration,取消选中Style>大括号:在同一行上

        6
  •  -3
  •   Peter Mortensen icecrime    4 年前

    在那里你可以搜索 格式化 选项,包括那些特定于语法的设置和间距。我认为它在文本编辑器选项附近。C/C++扩展只安装Visual C编译器和标准库,以及Windows SDK和其他一些东西。