Other answers are good, but it still took more time to figure out, so writing this one:
Steps:
- Open Visual Studio Code
- Press
Ctrl + ,
- Search
C_Cpp.clang_format_fallbackStyle
You will see a value of Visual Studio
(or, other if you have changed it before)
You can copy-paste, replace, with one of the below options:
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -2 }
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4 }
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4 }
{ BasedOnStyle: Google, IndentWidth: 4 }
LLVM
WebKit
I am using the 1st one
in the above list, which works great for my needs.
To revert to before, do the same steps as above, and copy-paste, replace below one:
You could also directly copy the above values into your \.vscode\settings.json
file, for example below line:
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: true, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -2 }"
Note:
- Since this is JSON, don't forget to have a comma at the end of the above line or before the above line, depending on if you have lines before/ after.
More details on clang format: