How to set per-filetype tab size?

Visual Studio-CodeVscode Settings

Visual Studio-Code Problem Overview


How to set tab size is already answered here.

But how to have different settings for different file types? E.g. I want the tab size for HTMLs to be 2, but for other files to be 4.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

VS Code configures language specific settings in settings.json

  • Shortcut is: Command Palette (⇧⌘P) then: Preferences: Configure Language Specific Settings

Example of setting.json changing tabsize

{
    "[sass]": {
        "editor.tabSize": 2
    },
    "[html]": {
        "editor.tabSize": 4
    },
    "[javascript]": {
        "editor.tabSize": 2
    }
}

These are not nested inside any other object, they are defined at the root.

Solution 2 - Visual Studio-Code

With vscode v1.63 you will be able to "group" languages in language-specific settings like this:

"[sass][javascript]": {
    "editor.tabSize": 2
},
"[html]": {
    "editor.tabSize": 4
}

This already can be done in the colorCustomizations setting like:

"workbench.colorCustomizations": {
	"[GitHub Sharp][GitHub Sharp Dark]": {
       "editorPane.background": "#d6d0d01a",
	   "sideBarSectionHeader.border": "#D3D3D3",
    }
}

See Multiple languages specific editor settings

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRonView Question on Stackoverflow
Solution 1 - Visual Studio-Coderandomguy04View Answer on Stackoverflow
Solution 2 - Visual Studio-CodeMarkView Answer on Stackoverflow