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
}
This question is related to
visual-studio-code
tabs
spaces
Ctrl+Shift+P, then "Convert Indentation to Tabs"
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
}
{
"editor.insertSpaces": true
}
True
works for me.
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)Below settings are worked well for me,
"editor.insertSpaces": false,
"editor.formatOnSave": true, // only if you want auto fomattting on saving the file
"editor.detectIndentation": false
Above settings will reflect and applied to every files. You don't need to indent/format every file manually.
In my case, the problem was JS-CSS-HTML Formatter extension installed after january update. The default indent_char
property is space. I uninstalled it and the weird behavior stops.
If you want to change tabs to spaces in a lot of files, but don't want to open them individually, I have found that it works equally as well to just use the Find and Replace option from the left-most tools bar.
In the first box (Find
), copy and paste a tab from the source code.
In the second box (Replace
), enter the number of spaces that you wish to use (i.e. 2 or 4).
If you press the ...
button, you can specify directories to include or ignore (i.e. src/Data/Json
).
Finally, inspect the result preview and press Replace All. All files in the workspace may be affected.
Source: Stackoverflow.com