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

你说的曾经没有我的故事 提交于 2019-11-26 22:04:48

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5876914/c-access-modifier-auto-indentation-in-visual-studio-2010-slowly-driving-me-cra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!