Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately. If this doesn't happen (it's a little lag sometimes), just reload or restart your VS Code.
By default, VS Code inserts spaces and uses 4 spaces per Tab key.
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:
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.
To change tab settings, click the text area right to the Ln/Col text in the status bar on the bottom right of vscode window.
The name can be Tab Size
or Spaces
.
A menu will pop up with all available actions and settings.
Ctrl+Shift+P, then "Convert Indentation to Tabs"
File
➤ Preferences
➤ Settings
or just press Ctrl + ,
editor.insertSpaces
F1
➤ type reload window
➤ press Enter)It's probably because of installed plugin JS-CSS-HTML Formatter
(You can check it by going to File
➤ Preferences
➤ Extensions
or just pressing Ctrl + Shift + X, in the Enabled list you will find JS-CSS-HTML Formatter)
If so you can modify this plugin:
Formatter config
➤ press Enter (it will open the file formatter.json
) 4| "indent_size": 1,
5| "indent_char": "\t"
——|
24| "indent_size": 1,
25| "indentCharacter": "\t",
26| "indent_char": "\t",
——|
34| "indent_size": 1,
35| "indent_char": "\t",
36| "indent_character": "\t"
File
➤ Save
or just press Ctrl + S)reload window
➤ press Enter)Check this from official vscode setting:
// Controls whether `editor.tabSize#` and `#editor.insertSpaces` will be automatically detected when a file is opened based on the file contents.
"editor.detectIndentation": true,
// The number of spaces a tab is equal to. This setting is overridden based on the file contents when `editor.detectIndentation` is on.
"editor.tabSize": 4,
// Config the editor that making the "space" instead of "tab"
"editor.insertSpaces": true,
// Configure editor settings to be overridden for [html] language.
"[html]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With