Currently in VSCode settings you can configure format on save as following:
"editor.formatOnSave": true
I want to exclude some file extensions, for example only format JavaScript but not HTML files.
Join Stack Overflow to learn, share knowledge, and build your career.
Currently in VSCode settings you can configure format on save as following:
"editor.formatOnSave": true
I want to exclude some file extensions, for example only format JavaScript but not HTML files.
You can use language specific settings to enable it for a specific language only, e.g. JavaScript:
"[javascript]": {
"editor.formatOnSave": true
}
To disable it for a specific language, you could switch the global default to true
and combine it with a language-specific false
:
"editor.formatOnSave": true
"[javascript]": {
"editor.formatOnSave": false
}
Note that language specific settings are based on language identifiers rather than directly on file extensions. There's an open feature request to allow for file extension specific settings as well.
In cases where the language ID isn't specific enough, "files.associations"
could be used to remap files with a specific extension and/or in a specific directory to another ID, but this will affect syntax highlighting, code completion, etc. as well. For instance, this would work to disable formatting for JavaScript files in out
directories, but they will be treated as plaintext:
"[javascript]": {
"editor.formatOnSave": true
},
"files.associations": {
"**/out/**/*.js": "plaintext"
}
*.in
files as plaintext ("files.associations": { "*.in": "plaintext" }
is that it disables code highlighting. Is there any way to disable formatting for *.in
files, but tell it to highlight as a certain language?
– Cole Johnson
Jul 5 '20 at 22:00
If you came across this question as I did because you were redirected because of this question VSCode : disable formatting of a specific file (or extension) which says, this is a duplicate (I don't feel so, because I wanted it for a specific file) and you're looking for a "one-time" solution:
VS Code has a shortcut "now" (I don't know since when) for saving a file without formatting listed under the command workbench.action.files.saveWithoutFormatting
- Default keybinding should be
CTRL + K CTRL + SHIFT + S
(simply keep CTRL pressed and then type K + SHIFT + S).
On OS X the default keybinding is
CMD + k
then press s
Cmd Shift P
to get to the quick commands and type save
.. then it will show the command 'Save without formatting'.
– Esger
yesterday
On Mac & Linux, use Ctrl + K S
On Windows, use Ctrl + K Ctrl + Shift + S
To check the VS Code keyboard shortcuts:Ctrl + K, Ctrl + S
(yes, almost the same as the above) and search for "save without formatting"
Create .vscode
folder in the root directory of your project if it is not there.
Create settings.json
file and add this line "editor.formatOnSave": false
in it.
{
"editor.formatOnSave": false
}
This way you can create a different set of settings for a specific project.
From VS Code IDE File -> Preferences - > Settings -> Text Editor -> Formatting and uncheck Format a file on save.
Ctrl + K Shift + S
On Linux, useCtrl + K S
– Joost van der Laan Jan 25 '20 at 10:36editor.formatOnSave
– KyleMit Dec 9 '20 at 1:18