Visual Studio Code never reopens previous file or folder

后端 未结 7 1384
走了就别回头了
走了就别回头了 2020-12-10 00:08

I have the exact opposite Problem of this question: Visual Studio Code always reopens previous file or folder

VSCode never seems to remembery my previously opened fi

相关标签:
7条回答
  • 2020-12-10 00:44

    Go to: Open File --> Preferences --> Settings and add "window.restoreWindows": "all" to your settings.json file. Remember to add a comma to the preceding statement.

    This will reopen all the windows you had open on the close of your last session.

    0 讨论(0)
  • 2020-12-10 00:49

    This will also work in case of unintended shutdown (like an OS restart for OS updates, or anything where VSCode is forcefully killed) with VSCode 1.42 (Q1 2020).

    See vscode/issue 12058 ("Save UI state periodically to prevent loss on shutdown") and PR 87158 with commit 54ab792, which includes the comment:

        // In some environments we do not get enough time to persist state on shutdown.
        // In other cases, VSCode might crash, so we periodically save state to reduce
        // the chance of loosing any state.
        // The window loosing focus is a good indication that the user has stopped working
        // in that window so we pick that at a time to collect state.
    

    bpasero adds in the issue:

    Pushed a change (#87158) that will:

    • save state every 60s
    • save state when the window looses focus

    The real fix is for Electron to provide API to detect the system shutdown case on Windows (e.g. what electron/electron#15620 suggests).

    These changes will probably not help when VSCode has focus and windows restarts, though in my testing it works when any non-vscode UI is popping up (e.g. some prompt from Windows to apply updates).
    I think this is the best we can do for now.


    Regarding the window.reopenFolders=all mentioned in issue 15949, the last (Sept 2020) comment illustrates it is not solved yet.

    Update Nov. 2020 for issue 15949 in VSCode 1.52:

    The sum of options in window.restoreWindows would then be:

    • preserve (new): all windows are restored, independent of how VSCode was started
    • all: all windows are restored, but not when you start VSCode on a file or folder
    • folders: only folders are restored, but not when you start VSCode on a file or folder
    • one: only a single window is restored, but not when you start VSCode on a file or folder
    • none: no window is ever restored

    I have pushed window.restoreWindows: preserve as new choice.
    all is still the default.

    See:

    New setting to restore previous session windows

    A new setting value preserve for the existing window.restoreWindows setting allows to enforce that every window you had opened before closing VSCode is restored when you start VSCode, even if VSCode is explicitly asked to open a specific folder or file.

    A common example is double-clicking on a file to open it in VSCode or using the terminal to open a specific file or folder.
    Without window.restoreWindows: preserve in that case, VSCode will only open the file or folder as instructed, but not restore any other window.

    0 讨论(0)
  • 2020-12-10 00:55

    They added this functionality in November 2016.

    Here is the setting for changing hot exit behavior:

    "files.hotExit": "onExit"
    
    0 讨论(0)
  • 2020-12-10 00:56

    So I needed that functionally too, currently it's just

    "window.restoreWindows": "none",
    

    in the settings.

    Controls how windows are being reopened after a restart. Select 'none' to always start with an empty workspace, 'one' to reopen the last window you worked on, 'folders' to reopen all windows that had folders opened or 'all' to reopen all windows of your last session.

    0 讨论(0)
  • 2020-12-10 01:00

    You could try the settings option:

    "window.reopenFolders": "all"
    

    This should reopen everything that was opened when you closed the editor, but I haven't tested it. I usually prefer that nothing gets reopened, so I use none. The default is one.

    0 讨论(0)
  • 2020-12-10 01:02

    It seems, VsCode only remembers opened files, if you also have a folder opened. It doesn't matter, if this is just a Dummy Folder somewhere on your drive - if you open files outside of this folder, they will be remembered aswell.

    I'm not sure if this is as designed, or a bug.

    Edit: This is a bug and tracked here

    Edit 2: To sum up the answers from below there are now two settings concerning this issue:

    Hot exit has been implemented, which restores files which weren't saved before VS Code is closed. To change this, use this setting:

    files.hotExit: "onExit"
    

    To reopen all files, use this setting:

    window.restoreWindows: "all"
    

    But there is still on open issue with this found here.

    ...

    0 讨论(0)
提交回复
热议问题