How to exclude one specific file from "format on save" in VSCode?

Viewed 511

There is a question about suppressing editor.formatOnSave for specific file extensions (languages) but I have a different question instead: how can I suppress this feature for one specific file in my workspace?

I want to suppress it in the repository somehow, with a config or hint in a comment, or some such, so I can prevent anyone from accidentally doing it wrong. I cannot tell my 20ish teammates to always "save without formatting", nor could I myself remember that at all times.

I have a ./vscode/settings.json file that has:

"editor.formatOnSave": true,

and it works wonderfully for all files in my workspace. However, I want to suppress it for my app-routing.module.ts file (it's an Angular project) because the auto-formatting there hurts readability more than it helps.

How to disable editor.formatOnSave for one specific file?

When I or a colleague use "Save" (CTRL + S on Windows) or "Save All" (CTRL + K, S on Windows) the auto formatting should not be triggered for that file.


What I've tried:

  • Check all answers in the related question (so e.g. "[javascript]": { "editor.formatOnSave": false }
  • Have a .vscode/settings.json folder in subfolders, but that's not supported
  • Include /* eslint-disable prettier/prettier */ in my file (AFAIK prettier is my formatter for TypeScript files), and read through this open prettier issue on GitHub
  • Create a .prettierignore file and add my file

None of these worked.

1 Answers

Just save your file with:

  • ControlK then S on Linux and Windows
  • ⌘ CommandK then S on Mac
Related