Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ access modifier auto indentation in Visual Studio 2010 slowly driving me crazy - can it be changed?

When programming C++ in Visual Studio, it insists on giving me these awful indentations on access modifiers - my condolences if anyone actually likes them this way ;) (a joke folks!)

public class MyClass
{
public:
   MyClass();
   ~MyClass();
   int wowAnInt();
}

Needless to say, I want this:

public class MyClass
{
    public:
       MyClass();
       ~MyClass();
       int wowAnInt();
} 


Is there any way to achieve this using anything (I've got ReSharper and Highlighter) or perhaps vanilla VS?

like image 711
Max Avatar asked May 03 '11 23:05

Max


People also ask

How to change Visual Studio formatting?

To access this options page, choose Tools > Options from the menu bar. In the Options dialog box, choose Text Editor > C# > Code Style > Formatting.

How do I turn on auto indent in Visual Studio?

Select the text you want to automatically indent.Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

What is indentation Visual Studio?

Visual Studio Code now includes an auto-indentation feature — which, as the name suggests, will automagically indent your code on the editor. The auto-indentation feature will automatically indent your code whenever you move a line around or a set of lines around.


2 Answers

There are two options to change that should help get the code looking the way you want. (Coming from Python, it really bothers me if stuff is not indented after a colon.)

I did use James McNellis's answer and change it from "Smart" to "Block", though I'm not sure how much that helped.

There is a setting under Tools -> Options -> Text Editor -> C/C++ -> Formatting -> Indentation -> Indent Access Specifiers which does indent the access specifiers, but doesn't indent the stuff after them.

I also chose "Do nothing" under Tools -> Options -> Text Editor -> C/C++ -> Formatting -> General -> When I paste, so that it doesn't change things just by copy/pasting.

This isn't a perfect solution, but it's at least a little bit closer.

like image 56
Pro Q Avatar answered Nov 04 '22 13:11

Pro Q


The closest you can get with the built-in Visual Studio editor settings is to change the indenting mode from "Smart" to "Block" (Tools -> Options -> Text Editor -> C/C++ -> Tabs -> Indenting).

When you do this, you can indent anything however you like, you just lose the "automatic indenting." Basically, whenever you press [enter] the new line will be indented the same number of tab stops / spaces as the previous line and it won't automatically reformat lines to get them to line up.

like image 33
James McNellis Avatar answered Nov 04 '22 13:11

James McNellis