5

I have recently discovered that Visual Studio likes to indent things after a template which takes up multiple lines, as you can see here:
indented class declaration
After the template, in which I like to list parameters on different lines to prevent one huge line, the class declaration is indented by a tab. It indents the whole class declaration, so possibly hundreds of lines end up indented unnecessarily.

This happens every time I use Visual Studio's auto formatting tool, which is rather annoying, as I do want to be able to use auto format (it's very helpful), but just not this specific "feature"(?). I've looked through all the options in Tools -> Options -> Text Editor -> C/C++ -> Formatting, but I have not managed to find one that fixes this issue.

How can I prevent Visual Studio from indenting code after multi-line templates like this?

MC ΔT
  • 483
  • 5
  • 12
  • What version of Visual Studio are you talking about? I just tried this with VS 2019 and it does not ident the class. – Hajo Kirchhoff Nov 07 '21 at 18:55
  • @Hajo VS2019 (16.11.5): https://i.stack.imgur.com/QNpYb.png, it only occurs when nested, not at the top level, so when in a class, struct, namespace etc. – Nick is tired Nov 08 '21 at 13:47
  • I'm surprised that Visual Studio still has this issue. Shortly after I asked this question I abandoned the hope of autoformatters working correctly for C++... – MC ΔT Nov 08 '21 at 16:08
  • Hm, fascinating. Indeed only in a namespace. I can confirm that this is still the case with VS2022. I guess one could create/edit a clangformat file but this really should work out of the box :) – Hajo Kirchhoff Nov 08 '21 at 19:28

0 Answers0