Format Curly Braces on Same Line in C++ VSCode
- Go Preferences -> Settings
- Search for C_Cpp.clang_format_fallbackStyle
- Click Edit, Copy to Settings
- Change from "Visual Studio" to
"{ BasedOnStyle: Google, IndentWidth: 4 }"
e.g.
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}"
- btw
ColumnLimit: 0
is helpful too, because google limit will break your code to next line when you do not need it.
If you want more:
- check https://clang.llvm.org/docs/ClangFormatStyleOptions.html
- customize your functionality to "C_Cpp.clang_format_fallbackStyle" for your favor.
More detail:
English: https://medium.com/@zamhuang/vscode-how-to-customize-c-s-coding-style-in-vscode-ad16d87e93bf
Taiwan: 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
Format C/C++ code with opening curly brace on the same line
Vscode ships with a version of the clang-format extension. As it is described in the vscode docs you can add a .clang-format
file to your workspace root that specifies style rules. How the .clang-format
file is formatted and which rules exist can be read here.
Instead (or in addition) you can use an existing style and just configure a few options. For that you either configure the BasedOnStyle property in your .clang-format
file or you can set the "C_Cpp.clang_format_style"
option in your vscode user settings.
In your case, to achieve the opening curly bracket on the same line, you can just use the Google's C++ Style. To enable it via the vscode settings, add the following entry to your user settings:
"C_Cpp.clang_format_style": "Google"
Visual Code C/C++ formatting of braces {}
In your VS Code settings should be able to do something like"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, BreakBeforeBraces: Custom, BraceWrapping: { BeforeElse: true }"
For more info:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
Visual Studio Code formatting for "{ }"
https://code.visualstudio.com/docs/cpp/cpp-ide
Related Topics
Fibonacci Sequence Overflow, C++
Special Characters in Visual Studio 2019 C++ Project and Executing Cmd Commands with Them
Do You Know Tool Building Tree of Include Files in Project\File
C++11 Cross Compiler/Standard Library Random Distribution Reproducibility
What Is the Role of Glbindvertexarrays VS Glbindbuffer and What Is Their Relationship
Cmake with Include and Source Paths - Basic Setup
How and When to Align to Cache Line Size
How Are Exceptions Implemented Under the Hood
What Does "-Wall" in "G++ -Wall Test.Cpp -O Test" Do
Vs: Unexpected Optimization Behavior with _Bitscanreverse64 Intrinsic
Why Simple Console App Runs But Dialog Based Does Not Run in Win Ce 6.0
How to Write and Read To/From a Qresource File in Qt 5