VSCode: How do you autoformat on save?

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.

If you are modifying other users code and your team don’t standardize a formatter, a nice option also is "editor.formatOnSaveMode": "modifications",. Unfortunately, the excellent black formatter does not support this feature.

Leave a Comment