在C ++ VSCode中在同一行上格式化大括号 [英] Format Curly Braces on Same Line in C++ VSCode
问题描述
我将 C ++扩展用于 VSCode (Visual Studio Code)。
目前,我已将设置为C_Cpp.clang_format_formatOnSave
设置为 true
。
当我保存我的C ++文件时,这种格式是我的代码。但是格式会在新行上产生花括号,而不是在同一行上。
$ b 当前C ++ VSCode格式化
for(int i = 0; i <10; i ++)
{
// ...
}
我想要的C ++ VSCode格式化代码看起来像
pre $
for(int i = 0; i <10; i ++){
// ...
}
我也有 editor.wrappingIndent
设置为same
。
如何在Visual Studio的同一行上使用C ++格式的花括号代码?
clang-format 是一个独立的工具,用于格式化C / C ++代码。附带 C / C ++扩展名,尽管您可以选择使用 C_Cpp.clang_format_path
选项在计算机上指定自己安装的clang-format版本的路径。
默认情况下,clang格式的源文件( C_Cpp.clang_format_style
)被设置为 file
code> .clang-format 文件。有关可用样式选项的更多信息,请参阅此页。
否则,您可能要查找的最简单方法是更改 C_Cpp.clang_format_fallbackStyle
。
你正在寻找的风格可能是 WebKit
。
因此,您的 .vscode / settings.json
文件应该是这样的:
code $ pre $ $ b
I'm using the C++ Extension for VSCode (Visual Studio Code).
Currently, I have the setting "C_Cpp.clang_format_formatOnSave"
set to true
.
This format's my code when I save my C++ file. But the format results in curly braces on new lines rather than on the same line.
Current C++ VSCode Formatted
for (int i = 0; i < 10; i++)
{
// ...
}
What I Want C++ VSCode Formatted Code to Look Like
for (int i = 0; i < 10; i++) {
// ...
}
I also have editor.wrappingIndent
set to "same"
.
How can I make curly braces in C++ format on the same line in Visual Studio Code?
clang-format is a standalone tool used to format C/C++ code. The C/C++ extension comes with it, though you have the option to specify the path to your own installed version of clang-format on your computer using the option C_Cpp.clang_format_path
.
The clang-format style source (C_Cpp.clang_format_style
) is set to file
by default, which reads in a .clang-format
file. See this page for more information about the available style options.
Otherwise, the easiest way that you are probably looking for is to just change the option C_Cpp.clang_format_fallbackStyle
.
The style you are looking for is probably WebKit
.
Hence, your .vscode/settings.json
file should look something like this:
{
"C_Cpp.clang_format_fallbackStyle": "WebKit"
}
这篇关于在C ++ VSCode中在同一行上格式化大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!