How can I detach the file explorer into another window? - visual-studio-code

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.

Related

See unsaved changes in vscode

Sometimes when closing vscode, or a tab therein, I get a dialogue asking "Do you want to save the changes you made to filename?" However, the unsaved edits are actually from a previous session that was closed without such a query, probably when turning off the computer, so I can't remember if it was meaningful edits, or maybe just an accidental key-press, like a shortcut gone wrong; and doing undo to revisit the last edits doesn't work either.
My question: How can I see the diff between the saved version of a file, and the version in the editor window? I think it would be nicest just to have a "show diff" option in the dialogue, but for now I'm also happy with a command line diff command.
I'm using ubuntu 20.04.
I'm using VSCode version 1.52.1 on MacOS and I had a similar problem that may not be the same problem, but I'm guessing it will work for you as well.
When you're in the Explorer view, in the upper left part of Explorer you have your "Open Editors." If that shows a dot to the left indicating that the buffer has changes in it, you can right click the file name and select "Compare with Saved." This will open another buffer to the side that will show you any unsaved changes.
To get rid of that window (it took me a bit to figure this out I'm sorry to say!), you can click the 'X' to the left of the extra buffer in "Open Editors."
Hope this works for you!
A few bright notes for the keyboard players out there:
The command you are asking about has a default shortcut. Unless you've applied a keyboard map extension, the Ctrl+Kd arpeggio opens the very same diff view between the active and saved versions of the current file. The default shortcut to close an editor tab (be it the diff or a file or anything at all) is Ctrl+W.
The command, like any command in VSCode, is also accessible via the Ctrl+Shift+P command dropdown (on Linux, F1 opens it too). Start typing e.g. compa sav (it saves your keyboard wear and tear to shorten words to a prefix which is unambiguous enough), and the list will shrink dynamically to just a few commands. Yours is File: Compare Active File with Saved. When it's close to the top enough, navigate the list of commands with the down arrow and execute it with Enter. As a bonus, you may click on the little gear to the right of the command currently highlighted in the list and redefine its shortcut, if you use it very often and prefer a chord shortcut to the default arpeggio one. Sorry, there does not seem to be a shortcut in lieu of the gear click. If there is, please let me know!
But if you really, really want to right-click on the filename in the Open Editors view of the Explorer sidebar, you can open that view directly with, you guessed it, a shortcut: Ctrl+Ke. And if you change your mind on a dime right at this moment, or realize that you in fact never had a mouse to do the right-click in the first place, use Shift+F10 to drop down the "right-click menu", properly called the context menu, which you navigate with arrows and execute with Enter (that's kinda a common theme, as you probably noticed). This works mostly anywhere the right-click does.
While in the Open Editors view, to switch to an editor file tab, move the selection to the desired file. Press Space to bring the file into view but stay in the Open Editors view, or Enter to bring the file into view and shift the keyboard focus to it. Pressing Ctrl+Shift+E brings focus back to the editor from any view in the Explorer sidebar. The same shortcut moves focus to the Explorer sidebar from the editor.
Happy ♬ k'boarding ♬!
ctrl+shift+P (or command+shift+P on mac) and fuzzy search for "compare changes with saved files"

VSCode cycle through opened files only within its own split window

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.

VSCode - Open terminals in a separate window

in VSCode is it possible to open the terminals in a separate window?
So far my research has pointed to a resounding NO but Im curious if anyone has a solution?
Move terminals between windows
It's now possible to move terminals between windows by detaching via
Terminal: Detach Session in one and attaching to another with
Terminal: Attach to Session. In the future this should help enable
cross-window drag and drop!
Lots of changes in v1.58: https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_58.md#terminals-in-the-editor-area
For v1.59 moving the terminal changes - including dragging and dropping onto another window, see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_59.md#drag-and-drop-terminals-across-windows
Drag and drop terminals across windows
Drag terminals from the tabs
list or editor area of one window into the tabs list, editor area, or
panel of another window.
Terminals in the editor area
Terminals can now be created in or moved to the editor area, enabling a multi-dimensional grid layout that persists and remains visible regardless of panel state.
To use terminals in the editor area, there are several options:
Create via the Create Terminal in Editor Area command.
Move a terminal from the panel to the editor by dragging and dropping from the tabs list.
Running Move Terminal into Editor Area with a terminal focused.
Moving into the editor area via the terminal tab context menu action.
The new terminal.integrated.defaultLocation setting can be set to editor to direct newly created terminals to the editor area by default.
Please Try:
File > Open New Window
Ctrl+Shift+P > Terminal: Create New Terminal in Editor Area
You can add keybinding to the commands as per your convenience.
i think that the OP wants to create a separate window for the terminal but still have the separated terminal linked to the code editor in the original window (that's what i want too). so that when you run the code in the editor the output is shown in the terminal in the separate window. but if you simply open up a new window of vscode and either open a terminal there or drag and drop the terminal from the original window into the new window, the new terminal is not the same session of the terminal. it is a separate independent unconnected terminal. running the code in the editor does not show output in the new separate terminal. all you have achieved is creating a new unconnected terminal. which you could have just accomplished by opening up a regular terminal window i.e. the one from windows os main menu, no need even to use vscode.
This answer is now outdated. See this answer for instructions on moving terminal panes between VS Code windows. This answer still works but is no longer a necessary workaround.
You can't detach the panes in VSCode, which IMO is a bit of a pain since Visual Studio can detach panes all day long.
There is a workaround though, you can open a new window in VSCode and maximize the terminal pane in that window.
One reason you'd want to do this is to have the Python terminal on a second monitor while still being able to use Python interactively (shift+enter way). Attaching/detaching didn't work for me, nor can you open separate terminals.
What you can do is simply resize your one window across the screen borders! Then right click on the terminal tab/header and click Move panel to the left and voila!
Try Сtrl+Shift+c.
For me, it opens the folder the script is within in a command prompt window.
Create a new window by going to File → New Window.
Open up a new terminal inside of it.
Go to your folder (cd your\projectfolder\path).
And here you are, you have a terminal for your project inside it's own seperate window.
You can change the terminal to be side-by-side instead of below the editor. And then make your window very wide. It is almost as good as having two windows.
Right click on the TERMINAL tab.
Select "Move Views to Side Panel"
Make your window very wide
It seems VS Code allows you to detach the terminal window, but it then will not show the output from the editor of the window you detached it from.
I have spent a while searching, and there is really no workaround other than to just run whatever file you are trying to debug from a separate terminal from the same CWD. This also means you will need to save the file in the window you are editing the file in every time you want to run it. huge pain.
If you are using PowerShell inside the VSCode terminal, why don't you use the PowerShell console from the start menu. It's basically equivalent to using the terminal in separate windows. Hope it helps.Sample

How can I navigate the VS Code Explorer & open a file via keyboard only?

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
...

Visual Studio Code open tab in new window

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.