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.
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.
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
I messed up my keyboard keys with VSCode. One alternative could be utilizing the VSCode commands to save without formating by doing CTRL+SHIFT+P and executing the
command. :)
On Mac, use ā + K, S
On 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"
You can use the below settings in Vscode and use "python.formatting.autopep8Args" to specify files or some pattern to ignore files you want. Of course, assuming that you are using autopep8 to format you python files other code formatters might have other ways to configure this.
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"python.formatting.autopep8Args": ["--exclude settings.py"],
"[python]": {
"editor.defaultFormatter": "ms-python.python",
"editor.formatOnSave": true
}
}
If anyone could have faced auto-format or format on saving for .env or other setting or environment file and it has a long string that caused an error and you are looking for a solution,
HERE IS IT (ADD THE BELOW IN YOUR VS CODE SETTINGS.JSON)
"files.associations": {
".env": "plaintext"
},
"[plaintext]": {
"editor.formatOnSave": false
},