- 以下包含兩個信息:
- 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格式有效