Is there any way to make Visual Studio stop indent

2019-01-22 00:51发布

Visual Studio keeps trying to indent the code inside namespaces.

For example:

namespace Foo
{
   void Bar();

   void Bar()
   {

   }

}

Now, if I un-indent it manually then it stays that way. But unfortunately if I add something right before void Bar(); - such as a comment - VS will keep trying to indent it.

This is so annoying that basically because of this only reason I almost never use namespaces in C++. I can't understand why it tries to indent them (what's the point in indenting 1 or even 5 tabs the whole file?), or how to make it stop.

Is there a way to stop this behavior? A config option, an add-in, a registry setting, hell even a hack that modifies devenv.exe directly.

7条回答
再贱就再见
2楼-- · 2019-01-22 01:48

Just don't insert anything before the first line of code. You could try the following approach to insert a null line of code (it seems to work in VS2005):

namespace foo
{; // !<---
void Test();
}

This seems to suppress the indentation, but compilers may issue warnings and code reviewers/maintainers may be surprised! (And quite rightly, in the usual case!)

查看更多
登录 后发表回答