4

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.

Shub
  • 240
  • 3
  • 11

2 Answers2

3

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.

Destroy666
  • 12,350
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.

hello
  • 1