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?
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.
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
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.
With Visual Studio 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.
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.
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).
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 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.
Related
Say I have 2 split windows with a few files opened in both of them as shown in the image below. I'm using the shortcut keys (on mac) "cmd+shift+[" or "cmd+shift+]" to cycle through all the opened files ("Open Previous/Next Editor"). However I was wondering if we could lock the "next" opened file that we will cycle to to be within the current split window that we are on?
i.e. Say right now I'm on 'window 2' (the split window on the right according to the image), pressing "cmd+shift+[" would bring the focus to the left split window and onto the "Untitled-4" file, but is there a way to prevent that and make it cycle to "Untitled-5" instead?
In Linux, I can use Ctrl+Tab or Ctrl+Shift+Tab to do this.
its actually the default behavior of vscode, it will cycle through opened files on the certain split window only. on the windows you could use ctrl+tab to do this
So I've found the option to perform what I wanted.
It's the "View: Open Next/Previous Editor in Group" command.
Can I somehow detach the file explorer and have it run in a separate program window rather than having it in the sidebar?
I was looking for this and I didn't find it either.
But I found an alternative way that helped me.
I'm going to share, because maybe it will help you too.
"Open active file in new window"
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.
Thus, you can keep the Explorer in one window and manipulate the files in the other.
I'm considerably new to Visual Studio Code and I am struggling a bit with an easy functionality. Imagine the case when I am reviewing some code in a file a.py and I select 'Go to definition' on a function x of the same file. Is there any possible configuration or shortcut that opens the definition on a split on the editor?
I have tried having already the same file split in the editor an it still opens the definition in the same file what is uncomfortable when you have to trace some code because you need to scroll up and down whenever you want to see another function of the same file.
An extension that allows to do the trick will also be well received. Thanks.
There are 2 ways to achieve this.
Either:
Left-click function name that you want to open.
Ctrl + t
Ctrl + enter
Or:
Change setting Editor > Goto Location: Multiple to be gotoAndPeek or goto
Ctrl + Alt + [click on function name]
Both methods will open the definition in the split to the right (or create a new split if this is the right-most split).
You like?
The shortcut is Ctrl+K, F12 but this can be changed in the shortcuts (search for shortcut editor.action.revealDefinitionAside)
More details here https://github.com/microsoft/vscode/issues/112136
For me setting workbench.editor.revealIfOpen to true like described here worked.
Controls whether an editor is revealed in any of the visible groups if opened. If disabled, an editor will prefer to open in the currently active editor group. If enabled, an already opened editor will be revealed instead of opened again in the currently active editor group. Note that there are some cases where this setting is ignored, e.g. when forcing an editor to open in a specific group or to the side of the currently active group.
[option + command + left click] or [option + command + F12] opens definition in split tab.
You have two different ways to do that task:
First one is, with the cursor on the word that you want to go to definition, press Alt+F12.
It opens a new tab like this one:
Second one is edit the settings and add this line:
"workbench.editor.enablePreview": false
It disables all the previews for code files so always that you want to go to definition, they will be open in a new tab, as you can see here:
I'm doing a code review of a project, which means cycling through all the files in it. I want to keep my hands on the keyboard but neither do I want to have to CMD+P and type in the name of each file.
I've bound CMD+K,CMD+E to workbench.files.action.focusFilesExplorer which enables me to easily get to the Explorer, but then I can only explorer.openToSide, which isn't exactly what I want. I want to be able to open them directly, full-screen even if I have other windows open.
Are there commands for this that I can bind to? I suspect this isn't a feature yet.
By default on a mac you can use cmd+down to open the file.
Pressing Enter will edit the filename.
To open a file, just press Enter once you've selected it. It's bound to the list.select command by default. This also works for expanding / collapsing folders.
After workbench.files.action.focusFilesExplorer you can press Up or Down to navigate through file list while File explorer is fosuced. Then hit Enter to open the selected file.
Also I set Ctrl + E for workbench.files.action.focusFilesExplorer.
In my case, sequential navigating through list of files is a repeating sequence of these shortcuts:
Ctrl + E
Down
Enter
...
Ctrl + E
Down
Enter
...
I'm wondering if there is a shortcut for VS Code that highlights in solution explorer tree current opened file. Like we have in Visual Studio:
Alt + Shift + L
Couldn't live with no complete answer, so figured out the following:
Without a direct keyboard shortcut:
Open the command palette via Cmd-Shift-P (or Cmd+P then >) and type Files: Reveal Active File in Side Bar.
This reveals the active file in the side bar similar to Visual Studio's Alt+Shift+L
Then, take the above and map a keyboard shortcut to it:
Open keyboard shortcut preferences file via Cmd-Shift-P followed by Preferences: Open Keyboard Preferences File.
Add in the following (taking Visual Studio's lead, I've personally mapped it to Alt+Shift+L, but map to what you want).
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "shift+alt+l",
"command": "workbench.files.action.showActiveFileInExplorer",
},
]
Note that it's not as good as Visual Studio, Atom, etc. in that you can't then navigate with arrow keys in the tree (arrow keys navigate the active file contents), but I guess I'll eventually figure out how to do that.
#Tomoyuki Aota points out that you can do the following to navigate with arrow keys:
After Files: Reveal Active File in Side Bar, press Ctrl+Shift+E (Show
Explorer). After that, I can navigate the files in the explorer by the
arrow keys.
I don't think there's a command for that, but there is a shortcut to enable/disable revealing the current file as you open it:
"explorer.autoReveal": true
Try this:
Together with #Rob's correct answer:
"explorer.autoReveal": true
then Ctrl-Shift-E (Show explorer) focuses that file in the explorer and the arrow keys will navigate up/down/left/right like any list. This works even if the explorer is closed prior to the Ctrl-Shift-E.
Ctrl-Shift-E has the added bonus in that it will toggle focus between the highlighted file and its editor as well.
For mac, use Cmd-Shift-E
Right-click the file tab (not necessarily current one) and click "Reveal in Side Bar".
I was able to achieve this by customizing the workbench.files.action.focusFilesExplorer command with keybinding Alt + shift + L
Open the Keyboard Shortcuts ctrl + K + shift + S
search for focusFilesExplorer command & customize
Provide your keybindings that you are used to - I set mine to Alt + Shift + L
F1 then type "reveal" also works from in VS Code, at least for me.
It looks like the actual version of VS Code offers a command for this feature now.
In the settings, type revealInExplorer in the search bar to find the command. There is no default keybinding, so just put your own. Works like a charm!
Download the open in browser extension, that's it.
Right click > Open in primary/secondary browser function appears, and the ALT+B / ALT+SHIFT+B shortcuts become available.
Had a similar case and ended up here looking for help.
I opened a file in "preview" mode after clicking a link in a .md file and wanted to know where this opened file was located in the project.
I found this button in the upper right corner of VS Code which was exactly what I wanted:
It's called "show source"
Also check "Explorer: Auto Reveal Exclude" patterns in VS Code settings. Files that fit any of the patterns will not be auto revealed in the Explorer tree.