Skip to main content

Autosave feature in VSCode

Tired of forgetting to save files in VS Code? Learn how to easily enable the Autosave feature, set it to onFocusChange, and never lose unsaved changes again!

· 2 min read
View raw
Christophe
Markdown, WSL and Docker lover ~ Insatiable curious.
Cet article existe aussi en français — lire la version française.

This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.

Autosave feature in VSCode

⚡
TL;DR

This article shows how to enable VSCode's Autosave feature, either through the Settings UI (Files: Auto save set to onFocusChange) or by adding the corresponding line to settings.json, so changes are saved automatically whenever the editor loses focus instead of relying on manual Ctrl+S.

How many times have you modified a file in VSCode (and forgotten to save the modification) in order to refresh it from your web page, run the script from your console, etc., and then thought Oh no, damn, it still doesn't work?

And it can take several minutes of back and forth before — damn it, silly me — you realize you didn't save your changes.

And even more so when you've done a Search & Replace in several files; some having been saved and others not — think of a multiple cursors session spread across a dozen tabs.

Let's see how to avoid this.

It's really easy: press CTRL-, (comma) to show the settings page and start to type autosave.

The concerned settings will be displayed and set Files: Auto save on onFocusChange.

Settings page

Or, you can also simply add the following line in your settings.json file:

{
"files.autoSave": "onFocusChange"
}

This is a VS Code settings configuration that tells the editor to automatically save files whenever the editor window loses focus—that is, when you switch to a different application or window.

You're using a versioning system, right?

Some people don't like this feature and say I want to be aware when I save something (in case I do something stupid eh) but, oh, there's a versioning system like Git isn't there? So if you do something stupid, just don't save the changes and/or do a revert.

If you're one of these people, try out the autosave function for a few days, and you'll see that it brings undeniable comfort.

Another setting in the same spirit, one you enable once and never think about again: Sticky scroll in VSCode.


Was this article helpful?
Did you try the steps in this article?