- 以下包含两个信息:
- VSCode修改配置文件的方法。
- 修改空格、Tab相关配置需要的配置项。
-
修改单个文件
如果只是修改当前正在编辑的文件的空格和tab设置,点击右下角状态栏中的Spaces: 4
即可进入设置界面。
但如果不想每个文件都修改一番,则可以通过设置全局的settings.json
配置,达到目的。 -
查询要用到的参数项
Ctrl+Shift+P
,输入settings.json
,选择Preferences: Open Default Settings (JSON)
,Enter
。
这个动作会打开defaultSettings.json
配置文件,不过这个文件是只读
的,也就是说我们不能修改。
他的作用只是:让我们知道有哪些参数项,分别有什么作用
。
我在其中找到的需要用到的配置项如下:
// Controls whether `editor.tabSize#` and `#editor.insertSpaces` will be automatically detected when a file is opened based on the file contents.
"editor.detectIndentation": true,
// Insert spaces when pressing `Tab`. This setting is overridden based on the file contents when `editor.detectIndentation` is on.
"editor.insertSpaces": 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,
我只修改其中的editor.tabSize
为2即可满足我的需求。
- 修改全局配置文件
settings.json
Ctrl+Shift+P
,依旧输入settings.json
,这次选择Preferences: Open Settings(JSON)
。
将自己的配置项加入即可。注意不要破坏配置文件的JSON结构
- 默认的
setting.json
内容
{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"window.zoomLevel": 0
}
- 我要加入的配置项:
"editor.detectIndentation": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
- 加入之后的
settings.json
{
"editor.detectIndentation": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"window.zoomLevel": 0
}
注意我是把新增的配置项加在开头。
如果你把配置加在结尾,那要注意最后一个配置项的value后面不要有逗号。且应该补全window.zoomLevel
配置项value后面的逗号。
保证JSON格式有效