Auto-saving files upon changes with VSCode

I have used WebStorm from JetBrains for almost 4 years now. It's a fantastic IDE for many reasons, but one of the best features is that it saves versions of files outside of version control. So if you accidentally delete files or lose files before they are saved by your VCS, WebStorm has a copy of them and there are visual diff tools to use. This feature has saved me on more than one occasion.

My question is - for VSCode is there some feature/plugin that will auto-save copies of files as they change? VSCode will save the files to some central location, or perhaps in the .vscode folder in the local workspace?

The feature in WebStorm is available from "Local History -> Show History" from a folder or file. Here is an article about it: https://blog.jetbrains.com/phpstorm/2012/10/using-local-history-for-code-changes-tracking/

The view looks like:

enter image description here


Solution 1:

you can go to menu Files and choose auto save.

enter image description here

Solution 2:

You can enable auto save with this methods:

1: check Auto Save item in File menu

visual studio code auto save activation

2: Go to Setting, then search auto save and select auto save option (afterDelay)

visual studio code auto save activation

Auto save description in vs code documentation

Solution 3:

Yes VSCode can auto-save changes on files as you make changes. It also allows you set a delay for how long to wait before saving the file.

Here's a link that should help you with that.

Or a shortcut you can simply navigate to your VSCode settings, and add the following to your settings.json

{
    ...
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 1000,
    ...
}

This will instruct your editor to autosave after 1000ms delay. You can set the autosave option to onFocusChange to autosave whenever you move your cursor away from the current text area.

Solution 4:

There's a package called Local History that can be used to save a backup of your files outside version control.

You should check that out.