Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to make Visual Studio stop indenting namespaces?

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.

like image 741
Thomas Bonini Avatar asked Sep 16 '10 14:09

Thomas Bonini


People also ask

Should namespaces be indented?

LLVM Coding Standards, https://llvm.org/docs/CodingStandards.html#namespace-indentation: In general, we strive to reduce indentation wherever possible. [...] To facilitate this and avoid some insanely deep nesting on occasion, don't indent namespaces.

How do I reduce indentation code in Visual Studio?

“shortcut to remove indent vscode” Code Answer and also indent backward using Shift + TAB.

What is indentation Visual Studio?

Visual studio's smart indenting does automatically indenting, but we can select a block or all the code for indentation. Select all the code: Ctrl + a. Use either of the two ways to indentation the code: Shift + Tab , Ctrl + k + f .


2 Answers

As KindDragon points out, Visual Studio 2013 Update 2 has an option to stop indenting.

You can uncheck TOOLS -> Options -> Text Editor -> C/C++ -> Formatting -> Indentation -> Indent namespace contents.

like image 182
user64953 Avatar answered Sep 21 '22 01:09

user64953


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!)

like image 22
bacar Avatar answered Sep 19 '22 01:09

bacar