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?
To access this options page, choose Tools > Options from the menu bar. In the Options dialog box, choose Text Editor > C# > Code Style > Formatting.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With