Auto-saving files upon changes with VSCode

Visual Studio-CodeWebstormJetbrains Ide

Visual Studio-Code Problem Overview


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

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

you can go to menu Files and choose auto save.

enter image description here

Solution 2 - Visual Studio-Code

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 - Visual Studio-Code

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 - Visual Studio-Code

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.

Solution 5 - Visual Studio-Code

Also, ensure you add .history to your .gitignore file so VScode doesn't track every change made to a single file as changes made to multiple files. This can be a problem and make your files changed so large even though it's a single file or a few files you made edits to.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexander MillsView Question on Stackoverflow
Solution 1 - Visual Studio-CodeSinaMN75View Answer on Stackoverflow
Solution 2 - Visual Studio-CodeHamed NaeemaeiView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeprotonView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeprotonView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeEzenagu EmmanuelView Answer on Stackoverflow