Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code files.autoSave onFocusChange not working

I'm trying to setup my visual studio code editor to auto save files on focus change.

Reading the setting documentation, I've set up my setting.json file for the project like this:

// Place your settings in this file to overwrite default and user settings.
{
    "files.exclude": {
        "**/*.js": { "when": "$(basename).ts"},
        "files.autoSave": "onFocusChange"
    }
}

But when I make changes to a file, then switch to a different file nothing happens (I still have to save the file manually).

What am I doing wrong?

like image 995
Miha Šušteršič Avatar asked May 05 '16 10:05

Miha Šušteršič


People also ask

How do I enable autosave in Vscode?

The easiest way to turn on Auto Save is with the File > Auto Save toggle that turns on and off save after a delay. For more control over Auto Save , open User or Workspace settings and find the associated settings: files.

Where is the unsaved file in VS code?

Show extension side bar within VS Code(Mac: Command + Shift + X , Windows and Linux: Ctrl + Shift + X ), type unsaved-files-vscode and press Enter and click Install .

How do I add autosave to Visual Studio?

AutoSave in Visual Studio 2022 Navigate from Tools > Options > Environment > Preview Features and Enable the autosave. Once you have Autosave Enabled, when Visual Studio loses focus, all the unsaved documents will be saved.


2 Answers

The option "files.autoSave" should be out of the "files.exclude" section.

   "files.exclude": {
        "**/*.js": { "when": "$(basename).ts"}
    },
    "files.autoSave": "onFocusChange"
like image 109
Kirill V. Lyadvinsky Avatar answered Oct 06 '22 08:10

Kirill V. Lyadvinsky


In VS Code, Enable the function using File > Auto Save

like image 30
wmc89 Avatar answered Oct 06 '22 09:10

wmc89