A lot of developers today work with multiple code editors. You might use one code editor while at work, and a different editor when you're working on an open source project at night. This tip shows how to use the EditorConfig extension to apply consistent code formatting while working with various code editors or team members.
- [Narrator] A lot of developers today work with multiple code editors, you might use one code editor while at work, and a different editor while you're working on an opensource project at night. And when you work with these different editors my guess is that you try to configure them, so they are consistent, that means that if you like to use spaces for your tab stops, you'd like to have that setting the same in all of your code editors. Here's some information about a concept called EditorConfig on their website. The main idea is that it let's developers define and maintain consistent coding styles between different editors and IDEs.
The way it does this is by defining a standard file format to use to define code formatting rules. If a code editor supports EditorConfig it reads this file and changes the settings in the IDE to match the values in the file. I'm in Visual Studio, and I've added that file to this console application. The naming convention is .editorconfig. And it's just a text file. In Visual Studio 2017, Microsoft added some incremental support for the concept and supports most of these settings.
So does the new Visual Studio code editor for developers still using older versions of Visual Studio like I am here in Visual Studio 2015, you can get EditorConfigs for it with a Visual Studio extension. I'll look for EditorConfig and this is the item here. I've already got it installed. If you don't have it installed click the download button or install button follow the instructions, and then restart the Visual Studio. As I said this is a text file, and it's got a few lines of text in here, root equal true, I won't talk about what that means, line four specifies that this applies to any file ends with a cs extension.
And then here I'm specifying some of my settings, indent style going to be a tab. Indent size is going to be two. And tab width is going to be two. If you go look at my code here in this Program.cs and turn on view white space. So you can see that I've got two spaces for my tabs, and when I indent, like I'll do over here and this Tip009.cs, And I indent this line, it indents two units.
Now what I'll do is I'll go into .editorconfig and change these to eight, save. And you go back to the file it doesn't look like anything's changed yet. You have to reopen this solution in order for it to read the .editorconfig settings. Now when I reopen it. You'll see that I've gotten much larger tabs spaces in both of my files. Now in this version that I have in Visual Studio 2015 it also, even though the editorconfig file's in this console application.
If you open up files and other projects, you'll see that those also have the same settings. You're supposed to be able to have specific editorconfigs in sub folders and have them take precedence, but in this copy of editorconfig it doesn't appear to be working at least not in Visual Studio 2015. So the takeaway from this is if you want to define these code editor settings, put an editorconfig file in your project, have the extension and now you can get consistency across multiple code editors.
Also those back to two, just cause that's the size that I prefer. And that's all I have for this tip.
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.