How to toggle (disable or enable) Auto Save in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
4 min

banner

# Table of Contents

  1. Toggle (disable or enable) Auto Save in VS Code
  2. Enable or disable Auto Save using the Command Palette
  3. Enable or disable Auto Save using the top menu
  4. Enable or Disable auto save in settings.json
  5. Enable or Disable auto save in a local settings.json
  6. Setting a keyboard shortcut for the Toggle Auto Save command

# Toggle (disable or enable) Auto Save in VS Code

To enable or disable auto save in VS Code:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type auto save and set the Files: Auto Save setting.

enable or disable auto save in settings

The Files: Auto Save setting has 4 values:

  • off - an editor with changes is never automatically saved (auto-save is disabled).
  • afterDelay - an editor with changes is automatically saved after the configured "Files: Auto Save Delay".
  • onFocusChange - an editor with changes is automatically saved when the editor loses focus.
  • onWindowChange - an editor with changes is automatically saved when the window loses focus.

If you pick the afterDelay value, you also have to configure "Files: Auto Save Delay" to set the auto save delay.

You can search for auto save delay and set the value. By default, the code is saved every 1,000 milliseconds (1 second).

files auto save delay

The Files: Auto Save Delay setting is only in effect if Files: Auto Save is set to afterDelay.

Make sure to specify a value in milliseconds (1000 ms = 1 second).

# Enable or disable Auto Save using the Command Palette

You can also use the command palette to toggle Auto Save.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type auto save and select File: Toggle Auto Save.

toggle auto save command palette

If at the time of running the command auto save was disabled, it gets enabled and vice versa.

Note that VS Code has a feature called local history that can be used to view and restore previous file versions.

# Enable or disable Auto Save using the top menu

You can also use the top menu to toggle auto save.

Click on File in the top menu and then click Auto Save.

Note that you might have to press Alt on Windows and Linux to show the top menu.

toggle auto save using top menu

Here is a short clip that demonstrates the process.

enable disable auto save using top menu

# Enable or Disable auto save in settings.json

You can also enable or disable auto save globally in your settings.json file.

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Set the files.autoSave property.

For example, if you want to disable auto save, use the following value.

settings.json
"files.autoSave": "off",

If you want to enable auto save, use one of the afterDelay, onFocusChange or onWindowChange values.

settings.json
"files.autoSave": "afterDelay", "files.autoSaveDelay": 1000,

If you pick afterDelay, you can also set the files.autoSaveDelay property.

enable disable auto save settings json

# Enable or Disable auto save in a local settings.json

If you need to set the auto save setting locally to your project, use a .vscode/settings.json file.

  1. In the root directory of your project, create a .vscode folder.

  2. Create a settings.json file in the .vscode folder.

  3. Add the following code to your settings.json file.

.vscode/settings.json
{ "files.autoSave": "afterDelay", "files.autoSaveDelay": 1000 }

set auto save in local settings json

If you need to disable auto save, set it to off.

.vscode/settings.json
{ "files.autoSave": "off" }

When the property is set in your .vscode/settings.json file it only applies to the current project.

# Setting a keyboard shortcut for the Toggle Auto Save command

If you need to set a keyboard shortcut for the File: Toggle Auto Save command:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Type auto save and double-click on the File: Toggle Auto Save row.

set keyboard shortcut toggle auto save

You can also click the row and then click on the plus icon to set a keyboard shortcut.

Once you specify a key combination press Enter to confirm.

For example, you could use something like Ctrl + F4.

toggle auto save ctrl f4

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.