32

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
croraf
  • 4,332
  • 2
  • 31
  • 50
  • 1
    As this is plugin-related, not directly VScode-related, you should ask the plugin author(s) directly: https://github.com/editorconfig/editorconfig-vscode/issues – herrbischoff Nov 23 '17 at 16:27

5 Answers5

18

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
croraf
  • 4,332
  • 2
  • 31
  • 50
  • 1
    @doublnt You have to click on the empty space as in the picture above – croraf Jun 04 '19 at 20:10
  • 3
    This solution worked for me. I copied my existing `.editorconfig` contents to the clipboard, deleted the file, right-clicked and selected `Generate .editorconfig`, and then pasted back the contents into this new file. Then the plugin started working properly. – gbmhunter Oct 28 '19 at 16:29
  • 1
    Remember to close the files and open them again. The settings will be working – Maicon Mauricio Jun 21 '21 at 00:54
  • 1
    If you try this and it seems like it worked (i.e. no error), but no file shows, you might need to refresh your explorer tree. VSCode might not pick up the newly added file straight away. – devklick Aug 16 '22 at 07:28
  • 1
    this solution is useless when it is for an entire team. for us intellij idea generated the .editorconfig and those who use vscode should use that one and not generate it. could you find anyway to tel vscode to start using the existing one? – Mohamad Eghlima Sep 02 '22 at 17:46
3

Try

root = true
[*.js]
indent_style = space
indent_size = 4
charset = utf-8
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
londox
  • 306
  • 2
  • 7
  • 3
    Why would that make a difference? An explanation would be in order. E.g., what is the idea/gist? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/48170568/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 01 '23 at 16:10
3

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

Viraj Singh
  • 1,951
  • 1
  • 17
  • 27
-1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BrahimS
  • 2,461
  • 1
  • 8
  • 2
  • 3
    Why would that make a difference? An explanation would be in order. E.g., what is the idea/gist? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/52201169/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 01 '23 at 16:11
-7

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mickey Puri
  • 835
  • 9
  • 18
  • 11
    I said in the question "I installed EditorConfig for vs code extension from the list of extensions." – croraf Feb 14 '19 at 17:32