I don't know why my code is auto formatted on save and for some reason changing the layout. I figured out this was due to auto format on save. How do I turn this off in Visual Studio Code?
7 Answers
For Windows
Here are the some basics steps to be followed to turn off auto complete.
Press Ctrl + Shift + P to open Command Palette. Then screen like below image appears.
Type
Save without formatting
and click the matching option available. It either commands on click or redirects you to next interface.
If it works on click then it's fine and if you are redirected to next screen just uncheck auto format option under onsave. For me it worked on cick to the shown command.
For Linux & Mac
CMD + K and then S
Default on Windows: Ctrl + k then Ctrl + Shift + s
-
What does this do exactly? Other folks here are using different OS's or might have remapped their keys or the default might change over time.– wjandreaCommented Jun 21 at 18:46
This was introduced in back in 2018, the keybinding (on MacOS) is:
Cmd+K S
For keybindings for your own system, search for the command saveWithoutFormatting
in the Command Palette
For others having the same problem and if Save without format is inconvenient to do every time and if you want permanent settings for saving without format here are the steps:
Edit the settings.json file. You can do that with the command "Open Settings (JSON)"
press Command + Shift + P (to open the command palette) and start typing the command "Open Settings (JSON)" and select from the suggestions.
The setting is named formatOnSave and you should set it to false, to disable it. It can be present multiple times for different types of things.
"editor.formatOnSave": false
It is best to search for "OnSave", because there might also be other settings that are doing formatting on Save, for example:
"editor.codeActionsOnSave"
-
1
As of 2023, none of the answers are satisfying enough
Go to File > Preferences > Settings
Type in the search bar
format on save
There you'll find the option Format on Save checked. Uncheck it and you're done!
NB: The advantage of this technique is that you're doing it once and for all, i.e. for all the files (unlike the one of Ctrl + Shift + P which does it for the current file)
-
1If you're posting a picture of text, please include the text itself, at least as an image description. I added one for you :)– wjandreaCommented Jun 21 at 18:55
If you don't want to open the command palette every-time, you can change the Ctrl/Cmd + S
shortcut to make the action "Save without Formatting"
and remove the shortcut for "Save".