简体   繁体   中英

How do I set up VSCode to NOT put curly braces on a new line?

Basically the opposite of this question:
How do I set up VSCode to put curly braces on a new line?

I am working with the PlatformIO extension for VSCode and whenever I format the document, I get all my curly braces misplaced on new lines, which looks horrible (coming from Java).

Similar question here , but it is asking about a specific C++ extension.

You can add a .clangformat file to your project. For example:

---
BasedOnStyle: Google
UseTab: Never
IndentWidth: 4
TabWidth: 4
BreakBeforeBraces: Attach
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
AccessModifierOffset: -4
ColumnLimit: 88
...

You can read about the options here: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Alternatively you can edit your vscode settings fallback style:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM