'VSCode - Disable ALL Auto Formatting on Save
I'm editing someone else's code and I only want to change 1 line of a 9000 line file. But every time I save, VS Code formats the entire file and removes any trailing white space. This is a no-no because when I push this up, the reviewer will have no idea which line to look at.
I've tried disabling prettier, adding all files to .prettierignore
, going into VS Code settings and disabling any suggestions of a formatter or white space trimming, turning off formatOnSave
.
Here is my .vscode/settings.json
{
"prettier.disableLanguages": [
"js",
"json",
"javascript"
],
"javascript.format.enable": false,
"typescript.format.enable": false,
"json.format.enable": false,
"html.format.enable": false,
"emmet.showAbbreviationSuggestions": false,
"css.validate": false,
"editor.defaultFormatter": null,
"editor.formatOnSave": false,
"[javascript]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": null
},
"editor.trimAutoWhitespace": false,
"diffEditor.ignoreTrimWhitespace": false,
"files.trimTrailingWhitespace": false,
"files.trimFinalNewlines": false,
"eslint.format.enable": false,
"files.autoSave": "off",
}
The only thing that seems to work is if I do CTRL + SHIFT + P
, then SAVE WITHOUT FORMATTING
. But what setting can I have so I can just do that with normal saving?
Solution 1:[1]
Did you try adding
"editor.formatOnSave": false
in your user settings rather than in your project settings?
Solution 2:[2]
Had the same problem, just bind 'cmd + s' to saving without formatting. press cmd+shift+p then search for save without formatting and click on the configure icon, then bind it with 'cmd + s', problem gone :)
Solution 3:[3]
In the case it is ESLint, and not Prettier, the solution is:
Open Preferences: Open Settings (JSON)
and configure:
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll.eslint": false
}
I don't have Prettier but the solution may be similar.
Solution 4:[4]
I came across this problem a while back. I disabled the formatOnSave
option in settings.
Goto File > Preferences > Settings
or Ctrl + ,
.
In User tab choose Text editor
and navigate
to Formatting
, disable the formatOnSave
option.
YW!
Solution 5:[5]
Perhaps this plugin called Formatting Toggle by tombonnike can help you.
It disables the autosave with a toggle.
From its description:
A VS Code extension that allows you to toggle the formatter (Prettier, Beautify, …) ON and OFF with a simple click.
Solution 6:[6]
I've just stumbled across this question while experiencing the exact same problem. The way I solved it, was just to switch the language of the document to plain text (you can do so by clicking on the language in the bottom navigation bar). If you then hit "save", no reformatting happens.
Disadvantage: You get no syntax highlighting. But if you just want to fix a typo or something and don't want to mess with the settings or install an extension, it's probably an ok workaround.
Solution 7:[7]
In my case I had two default code formatters that had conflicting settings, "prettier" was set not to format on save but JS-CSS-HTML Formatter was still set as my default formatter for some file types. I suggest using only one formatter and removing any unused / conflicting ones from your extensions list.
The way I used was to:
Open a file type ( one that's giving you formatting on save issues. )
Click on the file type and select "Configure 'yourFiletype' language based settings.. from the dropdown.
Delete the line that sets your default formatter: ex) "editor.defaultFormatter": "lonefy.vscode-JS-CSS-HTML-formatter"
Then go back to your file and try formatting normally, ( my hotkey is: alt + shift+ f ), it should prompt you to select your default formatter.
This should help minimize conflicting formatters issues.
Solution 8:[8]
Solution 9:[9]
In my case, I uninstalled prettier and was using html-css-js code formatter. I had already unchecked format on save, and had tried many other methods. I finally changed a setting in formatter.json (settings of html-css-js formatter) and then it worked.
Steps:
- ctrl + shift + P
- Formatter Config
- If "onSave": true, change true to false
- Save the formatter.json and reload window.
This worked for me. I can use auto-save after this as well.
Solution 10:[10]
Thanks to Guillermo's answer.
In VScode Goto File -> Preferences -> Settings -> (User tab) Text Editor -> Formatting -> Here uncheck the Format On Save
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Guillermo Brachetta |
Solution 2 | checkit |
Solution 3 | Romel Pérez |
Solution 4 | csgeek |
Solution 5 | rene |
Solution 6 | |
Solution 7 | Dharman |
Solution 8 | |
Solution 9 | |
Solution 10 | Harsha |