43

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 7

73

For Windows

Here are the some basics steps to be followed to turn off auto complete.

  1. Press Ctrl + Shift + P to open Command Palette. Then screen like below image appears.

    enter image description here

  2. 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

Sign up to request clarification or add additional context in comments.

Comments

30

Default on Windows: Ctrl + k then Ctrl + Shift + s

1 Comment

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.
22

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

Edit

For cursor users this is

Cmd+R S

Comments

11

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. VS Code command

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 Comment

It is best to search for "OnSave" this saved me.
3

As of 2023, none of the answers are satisfying enough

  1. Go to File > Preferences > Settings

    enter image description here

  2. Type in the search bar format on save

    enter image description here

  3. 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)

Comments

3

In mac you can save without formatting with the following shortcut, (No need to touch the config):

screenshot showing Command: "File: Save without Formatting", Keybinding: "Cmd K  S"

1 Comment

If you're posting a picture of text, please include the text itself, at least as an image description. I added one for you :)
1

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".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.