/config/vscode/format-on-save-settings
VS Code format on save: editor.formatOnSave and default formatters
The commands on this page have not been executed by our verification runner yet.updated 2026-10-20
- tool
- VS Code
- file
- settings.json (user) or .vscode/settings.json (workspace)
- key
- editor.formatOnSave
- type
- boolean
- default
- false
"editor.formatOnSave": true makes VS Code run the document formatter every time you save. Which formatter runs is decided by editor.defaultFormatter, globally or per language. Put the settings in the project's .vscode/settings.json so everyone who opens the repository gets the same behaviour.
A typical project setup
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"[makefile]": {
"editor.insertSpaces": false
}
}{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "charliermarsh.ruff"]
}extensions.json makes VS Code suggest the extensions the settings refer to.
Related settings
| Setting | Effect |
|---|---|
| editor.formatOnSave | format the whole file on save |
| editor.formatOnSaveMode | file (default), modifications or modificationsIfAvailable (only changed lines, needs source control) |
| editor.defaultFormatter | extension ID of the formatter to use |
| editor.codeActionsOnSave | run code actions such as ESLint fixes or organize imports on save |
| editor.formatOnPaste | format pasted text |
| files.trimTrailingWhitespace | remove trailing spaces on save |
If nothing happens on save, open the Command Palette and run Format Document With…: when several formatters are installed and none is the default, VS Code asks you to choose instead of formatting. The Output panel, channel of the formatter extension, shows its errors.
Sources
Related pages
commands · prettierprettier --write and --check: format files from the command lineFormat a project with npx prettier . --write, or fail CI on unformatted files with npx prettier . --check. Configure it with .prettierrc and .prettierignore.flags · eslinteslint --fix: automatically fix lint problemsnpx eslint . --fix applies the fixes that rules provide, such as let to const, and reports what it cannot fix. Preview changes first with --fix-dry-run.errors · makemake: Makefile:2: *** missing separator. Stop.GNU make stops with missing separator when a recipe line starts with spaces instead of a tab. Indent recipes with a real tab, or set .RECIPEPREFIX instead.