How do I turn off Visual Studio’s formatting options?

So I have this annoying issue with Visual Studio (when working with C#), I’ve been digging around in the C# formatting options, general VS options and on google and MSDN but can’t really find a fix for this – I’m assuming there’s just a checkbox somewhere and I’ve just overlooked it. Here it is:

I like to format my code like this:

Type var2    = new Type();
Type someVar = new Type();

But visual studio insists on formatting it like this, whenever the automatic format feature is applied:
Type var2 = new Type();
Type someVar = new Type();

Where do I turn this annoying feature off?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In the Formatting Options, In the Spacing section:

there is an option called ‘Ignore spaces in declaration statements’.
Check that option, and VS.NET will not re-format the declarations that you make.

So, this should work:

int i      = 5;
int melp   = 4;

But, when you do this, VS.NET will still reformat your code:
int i;
int melp;

i    = 5;
melp = 4;

will become:
int i;
int melp;

i = 5;
melp = 4;

So, it is really only in declaration statements that VS.NET will ignore the extra spacing you provide.

Method 2

Tools|Options|C#|Formatting

I. Ignore spaces in declaration statements <<– check this

AND

II. Set spacing for operators
Insert space…
Ignore spaces … <<– check this

Method 3

Tools -> options -> Text Editor -> C# -> Tabs -> “Keep Tabs”

Method 4

Look at Tools|Options|C#|Formatting


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x