typescript 将空格转换为制表符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36814642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert spaces to tabs
提问by Matan Yedayev
I'm writing TypeScript
and HTML
files, and tabs gets converted to spaces.
我正在编写TypeScript
和HTML
文件,制表符被转换为空格。
In my TypeScript
project, every tab converts to spaces, I want to turn it off, and have a tab instead of spaces.
在我的TypeScript
项目中,每个制表符都转换为空格,我想将其关闭,并使用制表符而不是空格。
This is my settings:
这是我的设置:
{
"editor.insertSpaces": false
}
EDIT 1:
编辑 1:
It seems to work in .html
files, but not in .ts
files.
它似乎适用于.html
文件,但不适用于.ts
文件。
回答by v-andrew
There are 3 options in .vscode/settings.json
:
中有 3 个选项.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.
editor.detectIndentation
从您的文件中检测到它,您必须禁用它。如果没有帮助,请检查您是否没有具有更高优先级的设置。例如,当您将其保存到用户设置时,它可能会被项目文件夹中的工作区设置覆盖。
Update:
更新:
You may just open File? Preferences? Settingsor use shortcut:
您可以只打开File吗?偏好?设置或使用快捷方式:
CTRL+,(Windows, Linux)
CTRL+ ,(Windows、Linux)
?+,(Mac)
?+ ,(Mac)
Update:
更新:
Now you have alternative to editing those options manually.
Click on selector Spaces:4at the bottom-right of the editor:
现在您可以替代手动编辑这些选项。
单击编辑器右下角的选择器Spaces:4:
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+Pand type:
如果要将现有 ws 转换为选项卡,请从 Marketplace 安装扩展
编辑:
要将现有的缩进从空格转换为制表符,请点击Ctrl+ Shift+P并键入:
>Convert indentation to Tabs
This will change the indentation for your document based on the defined settings to Tabs.
这将根据定义的设置将文档的缩进更改为制表符。
回答by Eric Bole-Feysot
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.
要更改选项卡设置,请单击 vscode 窗口右下方状态栏中 Ln/Col 文本右侧的文本区域。
The name can be Tab Size
or Spaces
.
名称可以是Tab Size
或Spaces
。
A menu will pop up with all available actions and settings.
将弹出一个菜单,其中包含所有可用的操作和设置。
回答by carlsborg
Ctrl+Shift+P, then "Convert Indentation to Tabs"
Ctrl+ Shift+ P,然后“将缩进转换为制表符”
回答by Alex Logvin
If you want to use tabs instead of spaces
如果您想使用制表符而不是空格
Try this:
尝试这个:
- Go to
File
?Preferences
?Settings
or just press Ctrl+, - In the Search settingsbar on top insert
editor.insertSpaces
- You will see something like this: Editor: Insert Spacesand it will be probably checked. Just uncheck it as show in image below
- 去
File
?Preferences
?Settings
或只需按Ctrl+, - 在顶部插入的搜索设置栏中
editor.insertSpaces
- 你会看到这样的东西:编辑器:插入空格,它可能会被选中。只需取消选中它,如下图所示
- Reload Visual Studio Code(Press
F1
? typereload window
? press Enter)
- 重新加载Visual Studio 代码(按
F1
?输入reload window
?按Enter)
If it doesn't worked try this:
如果它不起作用试试这个:
It's probably because of installed plugin JS-CSS-HTML Formatter
可能是因为安装了插件JS-CSS-HTML Formatter
(You can check it by going to File
? Preferences
? Extensions
or just pressing Ctrl+Shift+X, in the Enabledlist you will find JS-CSS-HTML Formatter)
(您可以通过转到File
? Preferences
?Extensions
或直接按Ctrl+ Shift+来检查它X,在启用列表中您会找到JS-CSS-HTML Formatter)
If so you can modify this plugin:
如果是这样,您可以修改此插件:
- Press F1? type
Formatter config
? press Enter(it will open the fileformatter.json
) - Modify the file like this:
- 按F1? 类型
Formatter config
?按Enter(它将打开文件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"
- Save it (Go to
File
?Save
or just press Ctrl+S) - Reload Visual Studio Code(Press F1? type
reload window
? press Enter)
- 保存(转到
File
?Save
或只需按Ctrl+S) - 重新加载Visual Studio 代码(按F1?输入
reload window
?按Enter)
回答by Vinicios Torres
In my case, the problem was JS-CSS-HTML Formatterextension installed after january update. The default indent_char
property is space. I uninstalled it and the weird behavior stops.
就我而言,问题是在 1 月更新后安装了JS-CSS-HTML Formatter扩展。默认indent_char
属性是空间。我卸载了它,奇怪的行为停止了。
回答by Rohan Kumar
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.
以上设置将反映并应用于每个文件。您不需要手动缩进/格式化每个文件。
回答by Xin
Check this from official vscode setting:
从官方 vscode 设置中检查:
// 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
}
回答by lama12345
回答by RealScatman
- Highlight your Code (in file)
- Click Tab Size in bottom righthand corner of application window
- Select the appropriate Convert Indentation to Tabs
- 突出显示您的代码(在文件中)
- 单击应用程序窗口右下角的 Tab Size
- 选择适当的将缩进转换为制表符
回答by ilovethedrama
{
"editor.insertSpaces": true
}
True
works for me.
True
对我来说有效。