The article explains how to specify coding style using EditorConfig in Visual Studio.
EditorConfig enables developers to define and maintain consistent coding styles across multiple editors and integrated development environments (IDEs). This allows you to configure each codebase to use project-specific text editor settings.
You can set your personal editor preferences in the Visual Studio Options dialog box. It overrides the .editorconfig
file settings.
Which Editors Supports EditorConfig
Some editors are initially bundled with support of EditConfig: Visual Studio, IntelliJ IDEA, PyCharm, WebStorm, CodeLite, GitHub, GitLab, Komodo, ReSharper, RubyMine.
Some other editors require the installation of EditConfig: NetBeans, PhpStorm, Visual Studio Code, Eclipse, Atom, Notepad++, C Lion, Code::Blocks, Emacs, Far Manager, Sublime Text, Textmate, Vim.
When you open a file in Visual Studio, the .editorconfig file settings will be used to help format the document.
Which Languages Supports EditorConfig
Supported languages and file extensions:
- C# – .cs, .csx, .cake
- Visual Basic – .vb
- Script – .sh, .ps1, .psm1, .bat, .cmd
- XML – .xml, .config, .props, .targets, .nuspec, .resx, .ruleset
- JSON – .json, .json5
- YAML – .yml, .yaml
- HTML – .htm, .html
- JavaScript – .js, .ts, .tsx, .vue
- CSS – .css, .sass, .scss, .less
- SVG – .svg
- Markdown – .md
- Visual Studio – .sln, .csproj, .vbproj, .vcxproj, .vcxproj.filters, .proj, .projitems, .shproj
How Configures Code Styling EditorConfig
You can configure the following properties with EditConfig:
- indent_style (available values: “tab”, “space”)
- indent_size (number of columns)
- tab_width (number of columns used to represent a tab character)
- end_of_line (available values: “lf”, “cr”, “crlf”)
- charset (available values: “latin1”, “utf-8”, “utf-8-bom”, “utf-16be”, “utf-16le”)
- trim_trailing_whitespace (available values: “true”, “false”)
- insert_final_newline (available values: “true”, “false”)
- root (special property at the top)
An .editconfig
file is divided into sections. Each section is specified for a specific file group, either using wildcards or by specifying specific files and folders. Some examples are provided below:
- The character set of all files is utf-8:
[*]
charset = utf-8
- Indentation for the *.bas (basic) files is 4:
[*.bas]
indent_style = space
indent_size = 4
- Identation for the *.cs (c#) files under the folder src is 2:
[src/**.cs]
indent_style = space
indent_size = 2
- Code styling refers to an array of files:
[{appveyor.yml, README.md}]
indent_style = space
indent_size = 2
How to Install EditorConfig
You can find instructions on how to install EditorConfig for several popular editors below.
Execute the CLI command to install EditConfig for Visual Studio Code:
dotnet new --install Boxed.Templates
dotnet new editorconfig
Apply the CLI command to install EditConfig for Atom:
apm install editorconfig
Run the CLI commands to install the EditConfig plugin for VIM:
mkdir -p ~/.vim/pack/local/start
cd ~/.vim/pack/local/start
git clone https://github.com/editorconfig/editorconfig-vim.git
For more details about EditorConfig follow the links:
Was this helpful?
0 / 0