Skip to main content

Note

If you are talking about prettier for tabSize, go to the Method 2 of this answer.

Method 1 (VS Code Way)

Well, if you like the developer way, Visual Studio Code allows you to specify the different file types for the tabSize. Here is the example of my settings.json with default four spaces and JavaScript/JSON two spaces:

PS: Well, if you do not know how to open this file (specially in a new version of Visual Studio Code), you can:

  1. Left-bottom gear →
  2. Settings → top right Open Settings

Enter image description here

{ // I want my default to be 4, but JavaScript/JSON to be 2 "editor.tabSize": 4, "[javascript]": { "editor.tabSize": 2 }, "[json]": { "editor.tabSize": 2 }, // This one forces the tab to be **space** "editor.insertSpaces": true } 

Method 2 (If using prettier)

If you are using prettier, things may be different again, prettier has 2 level of setting for this:

  1. User level, which you can click the extension and click setting find the keyword tabWidth
  2. Project level, which you can add/update from the root project level in file .prettierrc
Xin
  • 37.1k
  • 18
  • 89
  • 99