How to set the default indentation setting for Scala code in Microsoft VS Code

I was having a bear of a time trying to understand how to set the default indentation when editing Scala files using Microsoft Visual Studio (VS) Code, but I finally found the solution. The short story is that you want to edit the settings.json file, and add the code that I’ve made bold here:

{
    "editor.fontSize": 13,
    "workbench.activityBar.visible": false,
    "editor.minimap.enabled": false,
    "editor.tabSize": 4,
    "editor.insertSpaces": true,
    "[scala]": {
        "editor.tabSize": 4,
        "editor.insertSpaces": true
    }
}

Based on some things I read I thought the two lines above that bold code would work, but it did not, at least not for editing Scala source code files (it may work for editing plain text files or something else). I found the hint of this solution a couple of answers down on this SO page.

Once you make this addition to that file, then save and close it, your indentation should now be set to four spaces in Scala source code files.

How to open settings.json in VS Code

To get to the settings.json file I followed these steps:

  • While you’re in an editor panel on a Mac, press [Shift][Command][p]
    • Use [Shift][Control][p] on Windows
  • A search field appears; type “open settings” in that field
  • Select the “Preferences: Open Settings (JSON)” option
  • Now you should see some JSON text in an editor, like what I show above

In summary, if you want to set the default indentation setting for Scala code in Microsoft VS Code, I hope this is helpful.