I want to open the same folder in two different windows. I opened the folder in the first window, but when I tried to open the folder in the second window, VS Code just jumped to the first window, instead of opening it in the second window.
I want to do this because I want to divide my files into two windows and I am using VSCoq, which requires VS Code to open a particular folder to work.
This worked for me in VS Code 1.66.2
https://www.ryanchapin.com/running-multiple-vscode-windows-from-the-same-workspace/
CTRL+SHIFT+P
Then type
Workspaces: Duplicate As Workspace in New Window
open your folder as Workspace inside the new Window
CTRL+SHIFT+P
Workspaces: Duplicate As Workspace in New Window
Related
If I have a VS Code window open, and I double-click a file in the file explorer, it opens as a new tab in the same window. This is frustrating if the existing window is for a project and the newly opened file is unrelated. How do I force double-clicked files in the file explorer to open in a new instance of VS Code?
Go to Settings > Window > NewWindow.
Turn on 'open files in New Window' option.
Is it possible to associate a workspace with multiple windows? For example, when I open a workspace, can I have it open memorized documents in two windows? If I open a new window from an existing workspace, will it be opened under the same workspace with the same extensions enabled and disabled?
To duplicate your workspace in a new window see release notes, duplicate a workspace.
Duplicate Workspace in New Window
There is a new command Duplicate Workspace in New Window to duplicate
the current workspace in a new window. This command can be used as a
workaround to the current limitation that one workspace cannot be
opened in two windows. The workaround works best when you have the
setting files.autoSave set to afterDelay, onFocusChange, or
onWindowChange. In this way, the editor documents will be synced
through the file system when you have the same document open in
different windows.
The new window will have the same extensions enabled and disabled. But it will not open any files that you have already opened in the source window. Pay heed to the above link's comments about synchronizing your saves across windows.
You will need to bind the command to a keybinding, for example:
{
"key": "ctrl+alt+w",
"command": "workbench.action.duplicateWorkspaceInNewWindow"
}
Say I have a project/folder open in VS Code and I want to open the folder in Windows Explorer, is there keyboard shortcut or a VS Code Extension for that? Sometimes I also need to go to the project folder in command prompt.
In Visual Studio 2017, there's a menu option to open the folder and an extension for quickly getting to the project folder in command prompt -- see below:
How do I handle these in VS Code?
Right click on a file or folder from the left side explorer of VSCode, then select "Reveal in Explorer". Now you can see the folder in windows explorer.
How do we create a workspace in Visual Studio Code?
I see File menu commands to open, add a folder to and save a workspace, but nothing to create one.
The questions How can I create a workspace in Visual Studio Code? and How can I create a Visual Studio Code Python workspace? are specific to Python. I am asking how to create a generic workspace.
The question What is a 'workspace' in Visual Studio Code? provides some explanation of what they are, but it is not clear how to create them.
I had your same question, but the answer is simple, you don't. There is no need to start a blank workspace. To start on a new project use Open Folder from the File menu: navigate to the project, create a folder if needed, and then select the folder. You are now working on any files within that folder as if it were a workspace. If you leave and open another folder or workspace with files still open in editors, those files will be open when you open that folder again. Visual Studio Code making things work effortlessly! Until you do something that specifically requires a workspace you don't have to save it. If you save a workspace with no settings changed to the root folder here's what it looks like: {"folders": [{"path": "."}],"settings": {}}. That's it. The open editors are saved internally regardless of whether you saved as workspace. Starting by saving a blank workspace is like having an empty file cabinet in your office. VSCode will inform you if you ever need that and you can save a workspace then.
I finally had a chance to use VSC on a Mac. The difference on a Mac is
that Open File and Open Folder are under the same general Open
command (apparently because Macs use the same browser to select files and folders). Just use that to Open a folder, and open files in that folder workspace using the VSC explorer. All this still applies. The folder is the workspace.
You only need to save that workspace if you want to Add Folder to Workspace (in which case VSC will prompt you to save your multiroot workspace if you exit, or if you want to save settings specific to your project folder (though you can do that without a workspace using a settings json in a .vscode folder within). Even then VSC will auto save workspace settings for the folder internally when you haven't explicitly made the project folder a workspace.
Do you need a workspace and the extra .code-workspace file involved? If you have multiple root folders it's certainly nice to open the workspace and have those all there in your next session. If it's just for settings for a project with one root it's not needed (maybe if you want a file you can share with others on the project), and if the reason you are changing settings per project is language related then it may make far more sense to add language settings to your main settings file and have them in effect every time you work on that kind of project.
In short every time you use Open Folder workbench.action.files.openFolder you are essentially switching to another workspace.
In the folder you want to add to your workspace, create a file {foldername}.code-workspace and in the file put in the following code.
{
"folders": [
{
"path": "."
}
]
}
Save and close the file. Back in Visual Studio Code, click menu File → Open Workspace... and select the .code-workspace file you created and it will open it as a new workspace without having to add a folder to an existing workspace.
In the File menu choose "Open Folder...". Select a folder. You can add folders to the workspace using "File" | "Add Folder to Workspace...".
Optionally, also go to "File" | "Preferences" | "Settings". The "User Settings" tab will be open by default. Look for the "Workspace Settings" tab and select it. Modify a setting, such as change the theme.
Then you can save the workspace using "Save" in the File menu.
When you close the workspace using "Close Workspace" in the File menu then if you changed the theme for the workspace then the theme should revert to the global theme. When you re-open the workspace VS Code will open the folder(s) that were added to the workspace and apply whatever settings that were specified for the workspace. There are a few settings that are ignored for workspaces for security reasons but all other settings can be overridden in workspaces.
It is possible to add multiple projects to a workspace; see Multi-root Workspaces.
If you already have a window open with project files or folders, and you want a new workspace to work on a different project:
From the 'File' menu, choose 'New Window'
From the 'File' menu, choose 'Add Folder to Workspace' and choose the root folder of your project
The new window is the workspace for your new project. You can save it to a named file with 'File', 'Save Workspace As...'
(The above instructions refer to Visual Studio Code 1.36.1 on macOS.)
Close all open files in VS Code.
Select File menu >> Open Folder... and open the folder containing your source files.
Select File Menu >> Save Workspace as... it should default to the folder you previously opened. If not browse to it and save the workspace file.
To create a new workspace in Visual Studio Code press F1 (or Crtl+Shift+P) and choose 'AL: GO!'
Is there a property name that can be added to the settings.json for the default open/save location?
There is not. The workaround would be to create a shortcut to launch vscode with the location of the folder you want to open on startup. You can append a path as argument for VS Code to open.
In addition, VS Code will always remember the last folder you opened and restore it when you restart.
I found a solution. Edit the shortcut of VSCode and change the startup location.
On Windows:
Open Start Menu and locate Visual Studio Code
Right click on the Visual Studio Code icon
Select More >
Select Open File Location
Right click on the shortcut icon and select Property
Change the Startup Location to what you want
Save files to a default location in local machine with VS Code on Mac:
Here is a screenshot of how to get into VS preferences. Click VS community (on your menu bar) and the drop-down menu will display preferences. Within preferences, click on projects then load/save and you will find the default load/save locations.