Indentation does not match existing code (C #) in VS 2015

I have code in both C ++ and C #. In C #, since everything is in the class and is (at least usually) in the namespace, I do not backtrack for them, but start functions, declarations, etc. On line 1. In VS 2010, the IDE will back out first as deemed appropriate. I would move it back, and anything that would fit my preferences.

In VS 2015, each line is indented as if the containing function were indented by default, regardless of the actual indentation. For example, if I have lines:

x = 1; z = 3; 

and add the line in the middle, it will be automatically formatted 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 to the right so that everything matches the line added.)

I have the feeling of immersion that this is a β€œfunction” that cannot be changed.,.

+5
source share
1 answer

In the Tools | Options Tools | Options change

 Text Editor | C# | Tabs | Indenting 

from Smart to Block

You also need to tell VS to leave lines / blocks of code only when entering the character ';' or '}' . Turned off:

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

You can also play with options in

 Text Editor | C# | Formatting | Indentation 
+1
source

Source: https://habr.com/ru/post/1244024/


All Articles