VS Code: How to Open File in New Tab (Keep the Current File)
( 39 Articles)
In VS Code (Visual Studio Code), if you’re viewing a file in a tab and making no changes to it then this file will be closed if you open another file through the left sidebar. The reason is that the currently focused file is in the preview editor. Preview editors do not stay open and are reused until explicitly set to be kept open (e.g, via double-click or editing), and show file names in italics. This is helpful because you can quickly go through files and keep the workspace tidy.
However, sometimes you don’t need that. The two solutions below can help you always open a file in a new tab and keep the current file.
Turn off Preview Mode
1. Go to the Settings page of VS Code:
- Mac: Code > Preferences > Settings (hotkeys: Command + ,)
- Windows: File > Preferences > Settings (hotkeys: Ctrl + ,)
2. Type workbench preview into the search field then head to the Workbench > Editor: Enable Preview section. Uncheck the checkbox:
Now VS Code works as expected:
Note: If you’re using Safari, this demo video might not work nicely or not start at all. Please use Chrome, Edge, Firefox, or another web browser instead.
If you don’t want to change any settings, you can use hotkeys to open files and still keep the current file open even if it is unmodified. Just press Ctrl + O and the file you want to view from the dialog:
You’ve learned a couple of different ways to open a new file in a new tab in VS Code. This knowledge can help improve your productivity and coding experience in some way. If you’d like to explore more tips and tricks about VS Code, take a look at the following articles:
- VS Code: How to Pin/Unpin a File (2 Approaches)
- VS Code: How to Render Whitespace Characters
- How to Change File Encoding in VS Code
- VS Code: Opening Multiple Windows/Projects Simultaneously
- VS Code: Prevent Single-Child Folders from Being Merged
- VS Code: 3 Ways to Change Terminal Font SIze
You can also check out our Visual Studio Code topic page for more tutorials and examples.
Thank you. I love you.
I love you too