26

When I save files in VSCode, they are automatically formatted. Tab characters are converted to four spaces. But I prefer tabs. How can I force VSCode to use tab characters instead of four spaces?

These are my settings.

{
    "files.insertFinalNewline": true,
    "terminal.integrated.shellArgs.windows": [
        "-ExecutionPolicy",
        "Bypass"
    ],
    "files.trimFinalNewlines": false,
    "window.zoomLevel": 0,
    "explorer.confirmDelete": false,
    "workbench.startupEditor": "newUntitledFile",
    "typescript.updateImportsOnFileMove.enabled": "always",
    "typescript.format.semicolons": "remove",
    "editor.formatOnSave": true,
    "editor.detectIndentation": false,
    "editor.tabSize": 4,
    "editor.insertSpaces": false
}

What setting am I missing to force VSCode to not replace tab characters with 4 spaces?

birgersp
  • 3,909
  • 8
  • 39
  • 79

1 Answers1

35

In the settings editor, search for "indent" to find "Editor: insert spaces".

(This can be overridden on a language basis as well.)

Richard
  • 106,783
  • 21
  • 203
  • 265
  • 3
    Thanks! But my settings.json already has the `"editor.insertSpaces": false` line. This should disable the tab-to-spaces-replacing, I presume. It doesn't work for my Python files, for some reason... – birgersp Nov 26 '19 at 10:16
  • @gromit190 See the note in the settings: having space/tab detection on will override this. – Richard Nov 26 '19 at 11:38
  • 8
    `"editor.detectIndentation": false` - space/tab detection is off – birgersp Nov 27 '19 at 07:54
  • @gromit190 Check these settings are not overridden for Python. If they are not you might be hitting a bug (which might be language integration specific), Try asking in the issue tracker for the VS Code Python integration. – Richard Nov 27 '19 at 10:06
  • How can I check this? – birgersp Nov 27 '19 at 10:20
  • @gromit190 It is all in your `settings.json` (the settings editor has a button to open the underlying file: top right in the UI). (Note, as [Python's style guide](https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) says use spaces, it is possible the integration overrides your tab/space setting.) – Richard Nov 27 '19 at 11:01
  • Thanks! The settings must be overridden by Python style guide. Is there any way to configure the style so that it use tabs instead of spaces? – birgersp Nov 28 '19 at 07:54