croraf
croraf

Reputation: 4728

EditorConfig for Visual Studio Code

My project has .editorconfig file with:

[*.{js}]
charset = utf-8
indent_style = space
indent_size = 4

I thought this will force my Visual Studio Code to use indent style space with four spaces.

I installed the EditorConfig for Visual Studio Code extension from the list of extensions.

But still there isn't anything. My newly created files don't set automatically to the configured space style. What is the problem?

Upvotes: 41

Views: 84168

Answers (6)

janksmap
janksmap

Reputation: 71

You can achieve this by downloading the Format Files extension.

Once you install the extension, run the Start Format Files: From Glob command and use ** as the glob pattern. It will automatically format everything to comply with the .editorconfig file.

For example, I'm working on an Angular project and I wanted to change the indent size to 4 instead of 2 on the TypeScript files. So, after editing the .editorconfig file, I ran this command and used **.ts as the glob pattern. Worked like a charm!

Upvotes: 0

Viraj Singh
Viraj Singh

Reputation: 2358

An update for croraf's answer.

Step 1:

Install the EditorConfig for VS Code extension from the marketplaces.

Step 2:

after installing the extension, right click inside the project explorer window (don't right click on any of the files and folders, just outside them)

Step 3:

click on the "Generate .editorconfig" option and .editorconfig fill will be generated

editorconfig_SS

Upvotes: 6

croraf
croraf

Reputation: 4728

I think I found the solution. When I create the .editorconfig file with right-click on the folder structure sidebar in Visual Studio Code and select Generate .editorconfig (thus letting the plugin to create it), it works.

Click on the empty area below the files:

Enter image description here

Upvotes: 24

Mickey Puri
Mickey Puri

Reputation: 889

Visual Studio Code requires a plugin to use EditorConfig, so you need to install the plugin.

Upvotes: -9

BrahimS
BrahimS

Reputation: 2663

You can also try this one. You can change to spaces if you like :)

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 2

[*.{js,txt,md,css,html,php,py,json,yml,sass,pug}]
indent_style = tab
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false

Upvotes: -1

londox
londox

Reputation: 343

Try

root = true
[*.js]
indent_style = space
indent_size = 4
charset = utf-8

Upvotes: 4

Related Questions