In VSCode, if you want to exclude specific file extensions or languages from "Format on Save", you can achieve this by modifying the settings.json file. Below, I will explain how to do this in detail and provide a specific example.
Step 1: Open the Settings File
First, to modify the settings, you need to open the VSCode settings file settings.json. This can be done by following these steps:
- Open VSCode.
- Press
Ctrl + ,or click the gear icon in the bottom-left corner and selectSettings. - In the search bar, type
settings.json. - Click the
Edit in settings.jsonlink that appears in the results.
Step 2: Modify Settings
In the settings.json file, you can add or modify settings to exclude specific file extensions or languages. There are two key settings:
files.exclude: Used to exclude specific files or folders so they don't appear in Explorer or other places.[language]: Settings for specific languages, where you can add configurations such as disabling formatting.
Exclude File Extensions
If you want to prevent automatic formatting for specific file extensions on save, such as .min.js, you can set it as follows:
json"editor.formatOnSave": true, "[javascript]": { "editor.formatOnSave": true }, "**/*.min.js": { "editor.formatOnSave": false }
In this example, all JavaScript files are formatted on save by default, but files ending with .min.js are not formatted on save.
Exclude Specific Language
If you want to disable automatic formatting on save for a specific programming language, such as Python, you can set it as follows:
json"editor.formatOnSave": true, "[python]": { "editor.formatOnSave": false }
In this configuration, although global "Format on Save" is enabled, it is disabled for Python files.
Step 3: Save and Test
After setting this up, save the settings.json file and try modifying the corresponding file types to verify if the settings work. If the settings are correct, saving specific files or writing code in specific languages will not trigger automatic formatting.