visual-studio-codeformattingindentation

VS Code auto-format uses 2 spaces instead of 4


Whenever I let VS Code auto-format my code, it uses 2 spaces for the indentation instead of 4, even though apparently the default is 4 spaces, and I have not touched the settings.json.

The setting editor.tabsize also shows 4.

In the bottom right hand corner, it shows spaces: 4, but after auto-formatting, it shows spaces: 2, and will revert itself back to 2 no matter how many times I change it to 4.

Anyone know what's going on. This is happening with Ruby, if that matters.

Also, does anyone know of an alternate indenter/autoformatter for VS Code?


Solution

  • I think that you might have a problem with "Auto Detect Indentation". You should try to turn it off and see if that helps.

    // The number of spaces a tab is equal to. This setting is overriden based on the file contents when `editor.detectIndentation` is on.
    "editor.tabSize": 4,
    
    // When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
    "editor.detectIndentation": false