在使用Visual Studio Code时,如何自定义制表符到空格的转换系数?
例如,现在在HTML中,每按一次TAB就会产生两个空格,但在TypeScript中却产生4个。
默认情况下,Visual Studio Code会根据你打开的文件,尝试猜测你的缩进选项。
你可以通过"editor.detectIndentation": false
来关闭缩进的猜测。
你可以通过菜单文件→首选项→用户设置中的Windows的这三个设置,以及菜单代码→首选项→设置或⌘,
中的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
我运行的是1.21版本,但我想这可能也适用于早期的版本。
看看屏幕的右下方。你应该看到 "空间 "或 "标签大小 "的字样。
我的显示空格,--> ![在此输入图片描述][1] 。
1.点击 "空格"(或 "标签大小")。 2.选择 "使用空格缩进 "或 "使用制表符缩进"。 3.选择你喜欢的空格或制表符的数量。
这只适用于每个文档,而不是整个项目。如果你想在整个项目中应用它,你还需要在你的用户设置中添加"editor.detectIndentation": false
。