VS Code: How to Open File in New Tab (Keep the Current File)

Last updated on May 24, 2022 A Goodman Loading... Post a comment

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.

Alternative Solution

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:

Conclusion

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:

You can also check out our Visual Studio Code topic page for more tutorials and examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles