Stop Visual Studio Code From Closing the Current File When Clicking a New File to Open It.

Quick Fix

If you just want the quick fix for this issue: Uncheck Workbench > Editor: Enable Preview in Visual Studio Code’s Settings.

The Longer Explanation

The Visual Studio Code Editor’s default file open behavior is called “preview mode”. When preview mode is enabled, single clicking a file opens the file in preview mode and double-clicking a file opens the file in edit mode. If a file is open in preview mode, and no changes have been made to the file, then single-clicking another file will close the open file and open the new file. This can be frustrating in certain circumstances. I prefer my files to just open permanently when I click on them in the file explorer. Here’s how to shut that behavior off.

Disable Preview Mode in Visual Studio Code (Workbench › Editor: Enable Preview)

  1. Press the Ctrl+, keyboard shortcut or click File > Preferences > Settings to open the Settings window.

  2. Search for “preview mode” in the Settings search bar:

Search Settings for Preview Mode

Search Settings for Preview Mode

  1. Uncheck the box under “Workbench > Editor: Enable Preview”
Checkbox under Enabled Preview

Uncheck This Checkbox to Shut Off Preview Mode

  1. Visual Studio Code will show a vertical line next to the setting to indicate it has been changed.
Checkbox under Enabled Preview

Uncheck This Checkbox to Shut Off Preview Mode

  1. Close the Settings window

    The setting change will be automatically applied when the window is closed.

Once these instructions have been completed, Visual Studio Code will leave any file you click on open in the Editor window.


The postings on this site are my own and do not necessarily reflect the views of my employer.

The content on this blog is for informational and educational purposes only and represents my personal opinions and experience. While I strive to provide accurate and up-to-date information, I make no guarantees regarding the completeness, reliability, or accuracy of the information provided.

By using this website, you acknowledge that any actions you take based on the information provided here are at your own risk. I am not liable for any losses, damages, or issues arising from the use or misuse of the content on this blog.

Please consult a qualified professional or conduct your own research before implementing any solutions or advice mentioned here.