How to open a Tab in a new Window in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
6 min

banner

# Table of Contents

  1. Open a Tab in a new Window in Visual Studio Code
  2. Always open files in a New Tab in VS Code

Note: if you always need to open files in a new tab, click on the second subheading.

# Open a Tab in a new Window in Visual Studio Code

To open a tab in a new Window in VS Code:

  1. On Windows and Linux, press Ctrl + K, release the keys and then press O (the letter o, not zero).

  2. On macOS, press CMD + K, release the keys and then press O (the letter o, not zero).

You can also view the keyboard shortcut for the Show Opened File in New Window command for your operating system in this table in the docs.

If you hover over the key combination in the Key column, the keyboard shortcuts for all operating systems are displayed.

You can also use the Command Palette to view the keyboard shortcut:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type new window and view the keyboard shortcut for the File: Open active File in new Window command.

You can also select the command to run it directly from the Command Palette.

open active file in new window

# Changing the Keyboard shortcut for opening a Tab in a new Window

If you need to change the keyboard shortcut for opening a tab in a new window:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for new window and double-click on the File: Open Active FIle in New Window row.

change keyboard shortcut open file in new window

  1. Double-click on the row, specify your preferred keyboard shortcut and hit Enter to confirm.

You can also click on the pencil icon to set a new keyboard shortcut.

For example, you could use something like Ctrl + F4.

set custom keyboard shortcut open tab in new window

# How to open a Tab in a new Window using drag and drop

An alternative approach is to:

  1. Click on File in the top menu and select New Window.
Note that you might have to press Alt on Windows and Linux to show the top menu.

click on file new window

You can also use a keyboard shortcut to open a new window:

  • on Windows and Linux: press Ctrl + Shift + N.
  • on macOS: press Cmd + Shift + N.
  1. Drag and drop a tab from your existing VS Code window into the new window.

If you drag and drop a folder into the new window, all files from the folder get added to the new window.

You can also click on File in the new VS Code Window and then select Open File... or Open Folder....

file open file or folder

# Duplicating your project in a New Window

If you need to duplicate your project (workspace) in a new window:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type duplicate workspace and select Workspaces: Duplicate as Workspace in New Window.

duplicate as workspace in new window

By default, the command doesn't have a keyboard shortcut bound.

If you need to set one:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for wrap with abbreviation and double-click on the option.

duplicate workspace new window custom keyboard shortcut

# Always open files in a New Tab in VS Code

If you single-click on a file in Explorer (the left sidebar), VS Code opens the file in Preview mode.

Tabs that are in preview mode are not open, so if you click on a different file, the tab is not kept.

Here is a short clip that demonstrates this.

vscode opens files in preview mode

When I click on a different file, the current tab gets replaced.

Names of files that are in preview mode are written in italics, whereas files open in edit mode are not.

check if file is in preview mode

One way to open a file in edit mode is to double-click on it in Explorer (the left sidebar).

double click to open file in edit mode

If you always want to open files in a new tab:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings and select Preferences: Open User Settings.

open user settings

You can also open the settings screen by pressing Ctrl + , on Windows and Linux or Cmd + , on macOS.

  1. Type workbench enable preview and uncheck the checkbox of the Workbench > Editor: Enable Preview setting.

disable preview mode

Once you uncheck the checkbox, you will always open files in a new tab with a single left-click.

always open files in new tab

You can also disable the setting in your settings.json file:

  1. Press Ctrl + Shift + P (or Command + Shift + P on macOS).
Note: you can also press F1 to open the Command Palette.
  1. Type user settings json.

  2. Click on Preferences: Open User Settings (JSON)

preferences open user settings

  1. Paste the following line in your settings.json file.
shell
"workbench.editor.enablePreview": false,

disable preview in settings json file

Once you set the property to false, you will always open files in a new tab with a single left-click in Explorer.

# Specifying that you want to keep a tab open

If you don't want to disable preview mode altogether, you can right-click on a tab and select Keep Open to switch it to Edit mode from Preview mode.

right click keep open

You can also use a keyboard shortcut to move a file from preview mode to edit mode:

  • on Windows and Linux: press Ctrl+K, release the keys and then press Enter.
  • on macOS: press Ctrl+K, release the keys and then press Enter.

You can also view the keyboard shortcut for the Keep Open command in this table in the docs.

If the name of the file in the tab is not in italics, then it isn't in preview mode.

You can also use the Command Palette to switch a file to edit mode from preview mode.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type keep and select View: Keep Editor.

switch to edit mode from preview mode

The command gets the current tab out of preview mode.

You can also double-click on the file in Explorer to switch it out of preview mode.

An alternative way to get the tab out of preview mode is to simply save it:

  • on Windows and Linux: press Ctrl + S to save the file
  • on macOS: press Cmd + S

Once you save the file, it automatically gets taken out of preview mode.

I've also written an article on how to close the active Tab or all Tabs in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.