Visual Studio Code 格式化 "{ }"

我在32楼。 当我写代码时 C++ 在 Visual Studio Code 他自动像林茨一样


if /condition == true/
{
DoStuff//;
}


相反,我想做一些这样的事情:


if /condition == true/ {
DoStuff//;
}


我该怎么做?

我已经安装了

扩张 C/C++ 来自市场。
已邀请:

诸葛浮云

赞同来自:

基于答案 @Chris 画了。

前往设置 -> 设置

搜索 C_Cpp.clang_format_fallbackStyle

单击“编辑”按钮,复制到设置

变化。 "Visual Studio" 在
"{ BasedOnStyle: Google, IndentWidth: 4 }"


例如。


"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}"


顺便一提,
ColumnLimit: 0

也很有用,因为 google limit 当您不需要它时,将代码删除到下一行。

如果你想要更多:

退房
https://clang.llvm.org/docs/Cl ... .html
配置功能 "C_Cpp.clang_format_fallbackStyle" 为了你最喜欢的。

额外细节:

英语:
https://medium.com/%40zamhuang ... e93bf
台湾:
https://medium.com/%40zamhuang ... c57ce

涵秋

赞同来自:



文件

->

设置

->

设置

搜索
C_Cpp.clang_format_fallbackStyle


变化。 "Visual Studio" 在 "LLVM", "Google" 或者 "WebKit"

裸奔

赞同来自:

通常,我拥有自己几乎所有东西的方式 :/, 因此,我更喜欢最灵活的方式来实现这一目标。 在格式化方面,VS代码绝对是最灵活的编辑器 c++, 和 "easy".

这就是您必须做的是要自定义格式化。

创建一个名为的文件 .clang-format 在工作区的顶级文件夹中。

然后开始键入配置。 您可以参考页面。
https://clang.llvm.org/docs/Cl ... .html
, 找出各种可用选项。

保存文件,然后使用文档格式。 /Ctrl+Shift+I/, 或选择格式化 /Ctrl+K Ctrl+F/

这是我参考的文件。


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"

帅驴

赞同来自:

例如,使用 MacOS, 完美的设置方法
clang-format

对于VS-Code,首先要安装 clang-format 从 Homebrew:


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": "LLVM"



"C_Cpp.clang_format_fallbackStyle": "LLVM"



"C_Cpp.intelliSenseEngine": "Tag Parser"


它设置了格式化器
clang-formatter

, S.成立 Homebrew, 它从新创建的文件中自动提取您的样式设置
~/.clang-format

. 因此,您可以通过自己的样式更改每个参数,而不仅仅是它们的子集。

最后一个参数
C_Cpp.intelliSenseEngine

, 旨在绕过当前的拓展错误 C++, 违反了这一点 IntelliSense.

奔跑吧少年

赞同来自:

安装扩展 C# FixFormat

看法 > 扩张

搜索 "C# FixFormat"



Shift + Alt + F

如果它抱怨多种格式化,请按按钮。 Configure 并选择 C# FixFormat.

您可以通过进入文件返回新行上的卷曲括号 > 设置 > 设置。 然后向下滚动到 Extensions, C# FixFormat configuration 并取消选中复选框 Style > Braces: On Same Line

莫问

赞同来自:

我没有长时间使用它 Visual Studio, 但是您必须能够通过窗口选项卡打开选项菜单。

在那里,您可以找到参数

格式化

, 其中包括这些语法和间隔。 我认为这是在哪里 - 然后靠近文本编辑器设置。 延期 C/C++ 仅安装编译器 Visual C 和标准图书馆也是如此 Windows SDK 和其他几件事。

要回复问题请先登录注册