This article was translated from: How to customize the tab-to-space conversion factor?
How to customize the tab-to-space conversion factor when using Visual Studio Code? How to customize the tab-to-space conversion factor when using Visual Studio Code ?
For instance, right now in HTML it appears to produce two spaces per press of TAB, but in TypeScript it produces 4. For example, in HTML now, each press TABgenerates two spaces, but in TypeScript it generates 4 Space.
#1st Floor
Reference: https://stackoom.com/question/21lBk/ How to customize the conversion factor from tab to space
#2nd Floor
By default, Visual Studio Code will try to guess your indentation options depending on the file you open. By default, Visual Studio Code will try to guess the indentation options based on the file you open .
Via CAN Turn OFF Guessing by You Indentation "editor.detectIndentation": false
. You can "editor.detectIndentation": false
indent guess closed "editor.detectIndentation": false
.
You can customize this easily via these three settings for Windows in menu File → Preferences → User Settings and for Mac in menu Code → Preferences → Settings or ⌘,
: You can easily pass these three settings in the menu File menu code → Preferences → Set or customize this for Windows → Preferences → User Settings and for Mac ⌘,
// The number of spaces a tab is equal to. This setting is overridden
// based on the file contents when `editor.detectIndentation` is true.
"editor.tabSize": 4,
// Insert spaces when pressing Tab. This setting is overriden
// based on the file contents when `editor.detectIndentation` is true.
"editor.insertSpaces": true,
// When opening a file, `editor.tabSize` and `editor.insertSpaces`
// will be detected based on the file contents. Set to false to keep
// the values you've explicitly set, above.
"editor.detectIndentation": false
#3rd floor
I'm running version 1.21 but I think this may apply to earlier versions as well. I am running version 1.21, but I think this also applies to earlier versions.
Take a look at the bottom right-hand side of the screen. Take a look at the bottom right-hand side of the screen . Should See something that (Pic) by You Spaces
or Tab-Size
. You should see some of the name Spaces
or Tab-Size
.
Mine shows spaces,-> I show spaces,->
- Click on the
Spaces
(orTab-Size
) ClickSpaces
(orTab-Size
) - Choose
Indent Using Spaces
orIndent using Tabs
chooseIndent Using Spaces
orIndent using Tabs
- Select the amount of spaces or tabs you like. Select the amount of spaces or tabs you like .
This only works per document, not project-wide. This only applies to each document, not the entire project. If you want to apply it project-wide, you need to also add "editor.detectIndentation": false
to your user settings. If you want to apply it project-wide, you also need to add it in the user settings "editor.detectIndentation": false
.
#4th floor
By default, Visual Studio Code auto-detects the indentation of the current open file. By default, the Visual Studio code automatically detects the indentation of the currently open file. If you want to switch this feature off and make all indentation, for example, two spaces, you'd do the following in your User Settings or Workspace settings. If you want to turn off this feature and do all indentation (for example, two spaces) , You need to perform the following operations in the "User Settings" or "Workspace" settings.
{
"editor.tabSize": 2,
"editor.detectIndentation": false
}
#5th Floor
CAN WE Control by the Tab File size of the type with EditorConfig and the ITS Visual Studio Code Extension . We can use EditorConfig and Visual Studio Code extensions by file type control tab size . We then can make Alt+ Shift+ Fspecific to each file type. Then, we can make Alt+ Shift+ Fspecific to each file type.
Installation Installation
ext install EditorConfig
Example Configuration Example Configuration
.editorconfig .editorconfig
[*]
indent_style = space
[*.{cs,js}]
indent_size = 4
[*.json]
indent_size = 2
settings.json settings.json
EditorConfig overrides whatever settings.json configures for the editor. EditorConfig will override all settings.json configuration of the editor . Change IS NO need to There editor.detectIndentation
. No need to change editor.detectIndentation
.
#6th floor
You want to make sure that your editorconfig does not conflict with your user or workspace settings configuration, because I ’m just a little annoyed that when my editor configuration undoes these changes, no settings file settings are applied.