VSCode修改配置文件、设置tabSize并转换Tab为space

  • 以下包含两个信息:
    • VSCode修改配置文件的方法。
    • 修改空格、Tab相关配置需要的配置项。
  1. 修改单个文件
    如果只是修改当前正在编辑的文件的空格和tab设置,点击右下角状态栏中的Spaces: 4即可进入设置界面。
    但如果不想每个文件都修改一番,则可以通过设置全局的settings.json配置,达到目的。

  2. 查询要用到的参数项
    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即可满足我的需求。

  1. 修改全局配置文件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格式有效

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章