2

I've C/C++ extension of Microsoft as my default formatter. When I save/run my code the opening curly braces automatically move to newline instead of staying in sameline. How can I prevent this? (It doesn't happen after I disable the extension.)

In settings, I found an option position of opening braces for blocks that I set to sameline, but the braces keep moving to newline.

1

2 Answers 2

2

The extension is by default using ClangFormat formatter, which has this behavior of placing curly braces.

You can disable it with C_Cpp.formatting setting and then setup your own formatting rules.

You could also change the rules of ClangFormat with C_Cpp.clang_format_style setting or within .clang-format file. Read more about configuration here. Especially about BreakBeforeBraces.

1
  • 1
    Thanks :) I searched for C_Cpp.clang_format_fallbackStyle in Settings and changed it to { BasedOnStyle: Google, IndentWidth: 4 }. Now my braces are in sameLine.
    – Shub
    Oct 27, 2023 at 11:31
0

have you looked at the text editor settings? there is a setting for format on save. it was off by default for me, but maybe something happened with your vscode. try turning that off if it is on.

1
  • That's not quite a solution to disable all the formatting to avoid one problem.
    – Destroy666
    Oct 26, 2023 at 22:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .