Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indentation doesn't match existing code (C#) in VS 2015

I code in both C++ and C#. In C#, since everything is in a class and is (at least usually) in a namespace, I don't indent for those, but start functions, declarations, etc. in line 1. In VS 2010, the IDE would indent the first line in a class declaration as it thought appropriate. I would move it back, and everything following would align with my preferences.

In VS 2015, every line is indented as if the containing function was indented as per the default, regardless, regardless of the actual indentation. For instance, if I have the lines:

x = 1;
z = 3;

and add a line in the middle, it will auto-format as:

x = 1;
         y = 2;
z = 3;

(If I format the entire function by deleting and replacing the closing '},' the rest of the function will be shifted right so that everything matches the added line.)

I have the sinking feeling that this is a 'feature' that can't be changed. . . .

like image 406
Bob Bales Avatar asked Nov 08 '22 19:11

Bob Bales


1 Answers

From the Tools | Options dialog change the

Text Editor | C# | Tabs | Indenting

option from "Smart" to "Block"

You also need to tell VS to leave the lines/blocks of code alone when you type a ';' or '}' character. Disable:

Text Editor | C# |Formatting | General | Automatically format statement on ;
Text Editor | C# |Formatting | General | Automatically format statement on }

You might also want to play around with the options in

Text Editor | C# | Formatting | Indentation
like image 162
Michael Burr Avatar answered Jan 04 '23 03:01

Michael Burr