Tim
Tim

Reputation: 99408

Visual Studio's automatic indention

I am working on someone else's C# source files in Visual Studio 2015. Here is how I use indention in the IDE:

That creates a mixed use of tabs and four space combinations in the same source file, probably because the original author of the source files used different way to indent lines in their Visual Studio than I do via the IDE.

I wonder how I can make it consistent to use either tabs or four spaces for indenting every line, instead of mixing them in the same source files?

I followed https://msdn.microsoft.com/en-us/library/ms165330(v=vs.90).aspx, but couldn't find out if there is a setting for me to solve my problem.

Upvotes: 0

Views: 604

Answers (3)

Alireza Sadeghian
Alireza Sadeghian

Reputation: 429

Visual Studio has an Adaptive Formatting behavior which the Editor heuristically determines if the current file should use Tabs or Spaces for indentation.
You can turn this behavior off by going to Tools > Options > Text Editor > Advanced and uncheck “Use adaptive formatting”.

Upvotes: 0

The One
The One

Reputation: 4784

Try pressing

CTRL-K-D

It will properly indent all the code in your file

You can change the indent size, and a bunch of other things

Please check this link

https://blogs.msdn.microsoft.com/cdnstudents/2014/02/10/visual-studio-tips-and-tricks-formatting-your-code/

Upvotes: 3

Christian Gollhardt
Christian Gollhardt

Reputation: 17004

Simple press the following combination (while holding CTRL):

CTRL + K + D

This will automaticly reformat your code.

Upvotes: 3

Related Questions