Visual Studio Code - Convert spaces to tabs

Matan Yadaev picture Matan Yadaev · Apr 23, 2016 · Viewed 176.5k times · Source

I have both TypeScript and HTML files in my project, in both files tabs are converted to spaces.

I want to turn the auto-conversion off and make sure that my project has only tabs.

Edit:

With this setting it seems to work in HTML files but not in TypeScript files.

{
  "editor.insertSpaces": false
}

Answer

v-andrew picture v-andrew · Apr 23, 2016

There are 3 options in .vscode/settings.json:

// The number of spaces a tab is equal to.
"editor.tabSize": 4,

// Insert spaces when pressing Tab.
"editor.insertSpaces": true,

// When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
"editor.detectIndentation": true

editor.detectIndentation detects it from your file, you have to disable it. If it didn't help, check that you have no settings with higher priority. For example when you save it to User settings it could be overwritten by Workspace settings which are in your project folder.

Update:

You may just open File » Preferences » Settings or use shortcut:

CTRL+, (Windows, Linux)

+, (Mac)

Update:

Now you have alternative to editing those options manually.
Click on selector Spaces:4 at the bottom-right of the editor:
 Ln44, Col .  [Spaces:4] . UTF-8 with BOM . CTRLF . HTML . :)

When you want to convert existing ws to tab, install extension from Marketplace
EDIT:
To convert existing indentation from spaces to tabs hit Ctrl+Shift+P and type:

>Convert indentation to Tabs

This will change the indentation for your document based on the defined settings to Tabs.