0

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.

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
CW Holeman II
  • 4,661
  • 7
  • 41
  • 72
  • 2
    Getting the opening curly brace at the end of the `for` line shouldn't be a problem but you also show that the closing brace should be at the end of the last line in the brace enclosed block. I doubt there's a `clang-format` setting for that since it's a rather unconventional place to put it. – Ted Lyngmo May 30 '23 at 15:06

1 Answers1

0

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'.

CW Holeman II
  • 4,661
  • 7
  • 41
  • 72