Search code examples
c++visual-studio-codeformatclang-formatcurly-braces

Format Curly Braces on End Previous Line in C++ VSCode


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++) {
    // ...  }

How can I make curly braces in C++ format on end of the previous line in Visual Studio Code?

Not the same question as Format Curly Braces on Same Line in C++ VSCode.


Solution

  • There is an Artistic Style VSCode extension:

    Name: Astyle
    Id: chiehyu.vscode-astyle
    Description: Format C/C++/Obj-C/C#/Java code with Astyle in VSCode
    Version: 0.9.0
    Publisher: Chieh Yu
    VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=chiehyu.vscode-astyle
    

    which has Python/Lisp indenting format feature:

    --style=lisp / --style=python / -A12

    Astyle found from @mmj's comment to 'How to make clang-format keep closing braces on same line'.