Last updated: Apr 6, 2024
Reading time·6 min
Note: if you always need to open files in a new tab, click on the second subheading.
To open a tab in a new Window in VS Code:
On Windows and Linux, press Ctrl + K
, release the keys and then press O
(the letter o
, not zero).
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:
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.You can also select the command to run it directly from the Command Palette.
If you need to change the keyboard shortcut for opening a tab in a new window:
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.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
.
An alternative approach is to:
Alt
on Windows and Linux to show the top menu.You can also use a keyboard shortcut to open a new window:
Ctrl
+ Shift
+ N
.Cmd
+ Shift
+ N
.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....
If you need to duplicate your project (workspace) in a new window:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.By default, the command doesn't have a keyboard shortcut bound.
If you need to set one:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.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.
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.
One way to open a file in edit mode is to double-click on it in Explorer (the left sidebar).
If you always want to open files in a new tab:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
Once you uncheck the checkbox, you will always open files in a new tab with a single left-click.
You can also disable the setting in your settings.json file:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json.
Click on Preferences: Open User Settings (JSON)
settings.json
file."workbench.editor.enablePreview": false,
Once you set the property to false
, you will always open files in a new tab
with a single left-click in Explorer.
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.
You can also use a keyboard shortcut to move a file from preview mode to edit mode:
Ctrl+K
, release the keys and then press Enter
.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.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.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:
Ctrl
+ S
to save the fileCmd
+ 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.
You can learn more about the related topics by checking out the following tutorials: