Last updated: Apr 6, 2024
Reading time·4 min
To enable or disable auto save in VS Code:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
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).
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).
You can also use the command palette to toggle Auto Save.
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the 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.
You can also use the top menu to toggle auto save.
Click on File in the top menu and then click Auto Save.
Alt
on Windows and Linux to show the top menu.Here is a short clip that demonstrates the process.
You can also enable or disable auto save globally in your settings.json file.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
files.autoSave
property.For example, if you want to disable auto save, use the following value.
"files.autoSave": "off",
If you want to enable auto save, use one of the afterDelay
, onFocusChange
or
onWindowChange
values.
"files.autoSave": "afterDelay", "files.autoSaveDelay": 1000,
If you pick afterDelay
, you can also set the files.autoSaveDelay
property.
If you need to set the auto save setting locally to your project, use a
.vscode/settings.json
file.
In the root directory of your project, create a .vscode folder.
Create a settings.json
file in the .vscode
folder.
Add the following code to your settings.json
file.
{ "files.autoSave": "afterDelay", "files.autoSaveDelay": 1000 }
If you need to disable auto save, set it to off
.
{ "files.autoSave": "off" }
When the property is set in your .vscode/settings.json
file it only applies to
the current project.
If you need to set a keyboard shortcut for the File: Toggle Auto Save command:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.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
.
You can learn more about the related topics by checking out the following tutorials: