To save your files in Visual Studio Code without triggering the auto-formatting feature, follow these steps:
- Press Shift + Cmd + P (on macOS) or Shift + Ctrl + P (on Windows/Linux) to open the Command Palette.
- Type "save without formatting" in the Command Palette.
- Select "File: Save without Formatting" from the options.
This command will save your current file exactly as it is, without applying any of the configured formatting rules.
Why this works:
Visual Studio Code's Command Palette provides access to a wide range of commands, including specialized save actions. "Save without Formatting" bypasses the default save behavior that typically applies formatters based on your settings (e.g., editor.formatOnSave
).
Alternative approaches (and why they might not be ideal):
- Disabling
editor.formatOnSave
: While this prevents auto-formatting on every save, it disables the feature entirely. You might still want auto-formatting at times, just not on every save. You can find this setting in Settings ( Cmd + , on macOS or Ctrl + , on Windows/Linux) underEditor: Format On Save
. - Temporarily commenting out formatter settings: This is cumbersome and error-prone.
The "Save without Formatting" command offers a convenient and targeted solution when you specifically want to avoid auto-formatting for a particular save operation.