I am trying to open a tab in a new window in Visual Studio Code so I can move it to another screen. If I drag the tab the other screen, a file is created. Is there a shortcut to open a tab in a new Visual Studio Code window so I can move it to another screen?
-
24Feature request for floating window support in the same instance: github.com/Microsoft/vscode/issues/10121– Roy TinkerCommented Feb 1, 2018 at 19:28
-
1Try the following link as a workaround: [superuser.com/questions/1319288/vs-code-drag-tab-to-new-window/…– Miles BucktonCommented Oct 26, 2018 at 13:14
-
Related to stackoverflow.com/questions/29964825/… discussed on Meta meta.stackoverflow.com/questions/378537/… for possible merge.– SlateCommented Jan 4, 2019 at 17:18
14 Answers
On Windows and Linux, press CTRL+K, then release the keys and press O (the letter O, not Zero).
On macOS, press CMD+K, then O (without holding CMD).
This will open the active file tab in a new window/instance.
-
38
-
146
-
199that should be WAY easier. I should just be able to drag the tab to an empty space and it opens. Dropping the file is a much less useful feature. Commented Oct 25, 2017 at 13:53
-
43@light24bulbs - It's maddening that a tool for developers is so clumsy. This doesn't even close the existing tab (so now I have 2 copies open)! Commented Dec 11, 2017 at 8:47
-
46While handy, I'd like to point out to anyone wondering, this only opens the same file in a new instance of VS code. Changes aren't persisted either across instances. If I have a markdown doc open in one instance, and I "ctrl-k, o", it opens the same md doc in a new VS code, and opening the preview on one screen, the preview will not reflect changes from the other instance even after saving Commented Sep 11, 2018 at 18:40
This is a very highly upvoted issue request in Github for Floating Windows.
Until they support it, you can try the following workarounds:
1. Duplicate Workspace in New Window [1]
The Duplicate Workspace in new Window Command was added in v1.24 (May 2018) to sort of address this.
- Open up Keyboard Shortcuts Ctrl + K, Ctrl + S
- Map
workbench.action.duplicateWorkspaceInNewWindow
to Ctrl + Shift + N or whatever you'd like
2. Open Active File in New Window [2]
Rather than manually open a new window and dragging the file, you can do it all with a single command.
- Open Active File in New Window Ctrl + K, O
3. New Window with Same File [3]
As AllenBooTung also pointed out, you can open/drag any file in a separate blank instance.
- Open New Window Ctrl + Shift + N
- Drag tab into new window
4. Open Workspace and Folder Simultaneously [4]
VS Code will not allow you to open the same folder in two different instances, but you can use Workspaces to open the same directory of files in a side by side instance.
- Open Folder Ctrl + K,Ctrl + O
- Save Current Project As a Workspace
- Open Folder Ctrl + K,Ctrl + O
For any workaround, also consider setting setting up auto save so the documents are kept in sync by updating the files.autoSave
setting to afterDelay
, onFocusChange
, or onWindowChange
-
1This has a real problem for me suddenly. When I open the second window, that instance has no working directory. This makes all my linters go crazy, as they can't find references. Commented Nov 6, 2021 at 17:59
-
Unfortunately not compatible with debugging ;__; The new window or workspace has no knowledge of the other one. Breakpoints don't sync for instance. All I wish is to have local variables on one screen and my code on the other, as they don't fit side by side with a vertical monitor. Commented Aug 23, 2022 at 2:19
-
1Still open and locked. We can't even upvote on it anymore. Stuck in the backlog and ignored Commented Jun 2, 2023 at 8:04
-
When I want to split the screens I usually do one of the following:
- open new window with: Ctrl+Shift+N
and after that I drag the current file I want to the new window. - on the File explorer - I hit Ctrl+Enter on the file I want - and then this file and the other file open together in the same screen but in split mode, so you can see the two files together. If the screen is wide enough this is not a bad solution at all that you can get used to.
-
5Thanks @nisanarz this works but I think it would be more convenient if it would be possible to pop out the window like in Visual Studio. Also for the new window to act on the same code base when searching and opening new files.– doormanCommented Apr 12, 2017 at 7:18
-
couldn't make the other options work with unsaved files. This one works fine Commented Mar 7, 2023 at 8:41
-
I mean seriously, how is this not fixed yet? I know this is not an IDE, but so many IDEs I just drag the tab outside and it creates a new window automatically Commented Jun 2, 2023 at 8:02
-
This just duplicates the file and creates a new one. It does not preserve current changes if any Commented Dec 2, 2023 at 16:19
With Visual Studio Code 1.43 (Q1 2020), the Ctrl+K then O keyboard shortcut will work for a file.
See issue 89989:
It should be possible to e.g. invoke the "
Open Active File in New Window
" command and open that file into an empty workspace in the web.
If the accepted answer isn't working for you, for example, your shortcut key may have been changed to do other things. You can launch the command input by Ctrl + Shift + P
, then type 'new window' and you will see the result File: Open active tab in a new window
, and select it.
-
1
-
Press Command+K (wait, it will wait for pressing any key which you can see in the below bar) then press O.
So, it is Cmd+k+ O
(space represents little wait).
-
3
-
I do like the clarification on the status bar message :) Commented Aug 23, 2022 at 18:15
-
This clearly provided me a better understanding of what was really going on... Thank you!– RaiCommented Sep 18, 2023 at 21:44
Just an update, Feb 1, 2019: cmd+shift+n
on Mac now opens a new window where you can drag over tabs. I didn't find that out until I when through KyleMit's response and saw his key mapping suggestion was already mapped to the correct action.
-
1This is not the same thing as duplicating the workspace, though, because any dependencies or functions from libraries will not be loaded for your linters. A new windows lets you look at files, but it lacks all the functionality of a workspace.– mbomb007Commented Jan 10, 2020 at 15:26
I found a way to achieve the "Duplicate Workspace in New Window" workflow from @mbomb007's workarounds via the command line:
Normally code --new-window <path-to-folder>
will not open a new window if that folder is the root of an existing window.
code --new-window <path-to-some-file>
followed by code --add <path-to-folder>
does the trick. I put a 1s delay between those commands.
Issue #2686 was closed with a recommendation for users to use the "Duplicate Workspace in New Window" workflow, but didn't include a CLI solution. I would have posted this workaround there, but it's locked.
I wanted to use my second screen for viewing a preview of a document. None of the suggestions worked well since the preview was not updated in the second window, even when the workspace was duplicated and autosave enabled.
My workaround was to simply increase the size of the window to span both screens, and use the standard split tab.
To expand one window across two screens, I recommend Microsoft PowerToys. The FancyZones feature can be configured to allow zones to span across monitors, so a custom canvas can be created to quickly expand a single window to both screens.
You can find all issue tickets related to this feature by filtering with the workbench-auxwindow
("auxiliary windows") label in the issue tracker.
I'll try to keep this answer as up to date as I can with those developments.
VS Code 1.86 update
There's now a "Open Output in New Window" action in the Output Panel's title menu (source), and Notebooks are supported for floating windows (source).
VS Code 1.85 update
You can now drag editor tabs out of a window to create a new window for them. If you want to disable this, use the workbench.editor.dragToOpenWindow
setting.
Commands and keybinding command IDs include:
- View: Copy Editor into New Window (
workbench.action.editor.copyWithSyntaxHighlightingAction
) - View: Move Editor into New Window (
workbench.action.editor.moveEditorToNextWindow
) - View: Copy Editor Group into New Window (
workbench.action.editor.copyGroupToNextWindow
) - View: Move Editor Group into New Window (
workbench.action.editor.moveGroupToNextWindow
) - View: New Empty Editor Window (
workbench.action.newWindow
)
Terminals and search results are also supported in floating/auxiliary windows now too.
The right click / context menus of editor tabs now have the entries "Move into New Window" and "Copy into New Window".
VS Code 1.83/1.84 update
The VS Code team is now experimenting with implementation of floating windows in the latest VS Code Insiders (source: 1.83 release notes and 1.84 release notes). Quoting from the 1.83 release notes:
All editors across all windows operate on the same underlying editor models, so that changes made in one window are reflected live in all other windows. You can create any editor layout in the floating windows and open any editor you like, in as many windows as you want.
For our first working version, we envision that the Status bar would also be present in the floating windows so that editor information - such as line numbers and selection ranges - is shown. Stay tuned for more development in the coming months!
Currently, there is a command named View: Move Active Editor into a New Window (Experimental)
with ID workbench.action.experimentalMoveEditorIntoNewWindowAction
(if you want to bind a keyboard shortcut to it).
VS Code 1.82 answer
As for right now in the stable release of VS Code, the best workaround I see is to use the File: Open Active File in New Window
command, which is bound by default to ctrl/cmd+k,o, or to manually open a new window, and drag the editor over there. But those aren't great because the file will be opened standalone, without any of the context of the workspace it was opened from (without workspace settings, extensions enabled for that workspace, workspace tasks, project configuration for that workspace, etc.). If you don't want that problem, then you can open the same workspace in a new window. I guess the downside of that could be that it could potentially use more system resources (Ex. extension host, filesystem watchers to keep the multiple windows with the same workspace in sync, etc.).
I thought I'd take the opportunity to highlight comments from the issue ticket that explain what makes this a hard problem to tackle / hard feature to implement (seriously- this is why I tell people not to make "+1" / "bump" comments. that thread is a swamp and an absolute nightmare to try to read through if you want to actually find the meaningful discussion). According to the maintainers, the challenge mostly comes difficult architecture changes and keeping good performance (source).
https://github.com/microsoft/vscode/issues/10121#issuecomment-287059917
https://github.com/microsoft/vscode/issues/10121#issuecomment-345497635 TL;DR: Chromium's process-isolation makes this harder to implement.
https://github.com/microsoft/vscode/issues/10121#issuecomment-345770248 TL;DR: Each piece of the workbench would need refactoring to be self-contained, the master window would need to know what window each of its parts are in, and several services like the extension host would need to be moved into a shared backend that each window can communicate with (I wonder if the sandbox work helps with this?).
-
1Isn't it basically resolved in 1.85 ? They have closed the issue as completed. Thanks.– Hagrid67Commented Dec 28, 2023 at 22:01
-
@Hagrid67 The feature will continue being developed and improved upon. See the link in the very first sentence of this answer post. The initial implementation may be considered done, but the feature in general is far from being "finished" and my never be (and that can be a good thing)– starballCommented Dec 28, 2023 at 22:03
-
As of 1.85, this should be the accepted answer. The only solution that lets you use the debug console in one window and place breakpoints in another one. Commented Jan 8 at 14:54
Thanks to a recent update in VSCode, you can now just drag the file to an empty location and it will popup a new window! (Provided your VSCode version is > v1.85.x)
I am personally running VSCode in WSL2 and it works great for me!
Here is a demo - it is available in Insiders now - of the ability to open an editor in a new window as mentioned by @starball.
There is this setting which is enabled by default:
Workbench > Editor: Drag to Open Window
Controls if editors can be dragged out of the window to open them in a new window. Press and hold Alt-key while dragging to toggle this dynamically.
This means that you could disable that setting but still drag and drop an editor or editor group to create a new file by also holding down the Alt key at the same time.
You can either drag an editor (or an editor group) out of the current window to open all of them in a new window OR use a command on the current editor.
The commands are
View: Move Editor into New Window
workbench.action.moveEditorToNewWindow
workbench.action.experimentalMoveEditorIntoNewWindowAction
View: Move Editor Group into New Window
workbench.action.moveEditorGroupToNewWindow
View: Copy Editor Group into New Window
workbench.action.copyEditorGroupToNewWindow
View: Copy Editor into New Window
workbench.action.copyEditorToNewWindow
Those currently do not have a default keybindings.
In addition, each editor tab's context menu includes 2 new options:
Move into New Window
Copy into New Window
The editor group tab bar also includes these context menu options, see demo:
The Copy
versions will make another copy of the current edit group or editor in a new window without removing them from the original window.
Tabs can be dragged back and forth between the new window and the main workspaces window. The floating window has no views or panels associated with it - like the SideBar or Panel where the terminal typically lives.
Demo using the editor move command:
On a drag and drop (currently on dragging it appears as if it cannot be dropped - ignore that for now, it can be dropped) the new window's top left will be located where it is dropped.
Demo showing dragging an editor group:
Note that to drag an entire group you start from the area to the right of the group - click and drag.
To drag an individual file click and drag from it's tab.
You can have mutiple floating or detached windows open, and you can drag editor tabs between them.
For multiple monitors, you can have the windows on any of the monitors but a new window created by command or context menu option is created on the same window. To actually get a new window to another monitor you have to drag and drop it there.
You can also hit Win+Shift+[n]. N being the position the app is in the taskbar. Eg if it's pinned as the first app hit WIn+Shift+1 and windows will open a new instance and then you can drag the tab over to the new window.
Most convenient workaround for me so far.
If you are using the excellent
VSCode for Mac, 2020
simply tap Apple-Shift-N (as in "new window")
Drag whatever you want there.