VSCode: How do you autoformat on save?

后端 未结 3 1903
無奈伤痛
無奈伤痛 2021-02-18 15:01

In Visual Studio Code, how do you automatically format your source code when the file is saved?

3条回答
  •  遥遥无期
    2021-02-18 15:42

    Enable "Format On Save" by setting

    "editor.formatOnSave": true
    

    And since version 1.49.0 editor.formatOnSaveMode has the option modifications that will just format the code you modified. Great when you change someone else code.

    You can also set it just for one specific language:

    "[python]": {
        "editor.tabSize": 4,
        "editor.insertSpaces": true,
        "editor.formatOnSave": true #
    },
    

    Since version 1.6.1, Vscode supports "Format On Save". It will automatically use a relevant installed formatter extension to format the whole document.

提交回复
热议问题