Wizard
Wizard

Reputation: 22113

Open the same directory twice

On command line, I could open a directory like:

code .

Now, I want two of the identical diretory opened and displayed in another window.
(It's not spliting the editor)
Then, I tried again.

code .

Nothing happened.
There's still one directory opened.
How to achieve such a task?

Upvotes: 294

Views: 122552

Answers (11)

user12422568
user12422568

Reputation:

In VSCode 1.84.2, simply File > Duplicate Workspace in Menu Bar.

enter image description here

Upvotes: 8

vijay abba
vijay abba

Reputation: 1

If you want a window to display on all virtual desktops

Method: 1

  1. win + tab then right click on vs code.
  2. List item select show this window on all desktops option.

you can see vs code in all virtual desktops

Method: 2 Simply duplicate the workspace

  1. crtl + shift + p
  2. search 'duplicate as workspace in new window'

ā†˜ļø see image šŸ‘ļøšŸ‘ļøšŸ–¼ļø see image šŸ‘ļøšŸ‘ļøšŸ–¼ļø

enter image description here

Upvotes: 0

Lightfire228
Lightfire228

Reputation: 616

After some fiddling, I figured out how to do this via the CLI

# open the first window
code <folder>

# force open a new window
code -n

# tell vscode to attach the target folder to the last active window
code -a <folder>

alternatively, if you do this a ton, you can just create a .code-workspace file for the duplicated workspace, and then simply

code <folder>
code <folder-dupl>.code-workspace

Creating the workspace is simple, just open the folder in vscode, open the command palette (F1), and search for "Workspaces: Duplicate as Workspace in New Window"

Then in the new window, simply open the command palette and search for "Workspaces: Save Workspace As..."

The benefit of this, is that the duplicated workspace is now "named", and will not ask to save the new workspace configuration every time you close it

Upvotes: 1

You can do this with the following ways:

1- Manually open a new window (ctrlshiftn) and go to:

File > Add folder to Workspace. Then just select the folder.

2- Open the command panel (ctrlshiftp), enter dupl, and select Workspaces: Duplicate Workspace in New Window

Source: https://code.visualstudio.com/docs/editor/multi-root-workspaces

Upvotes: 565

Shital Shah
Shital Shah

Reputation: 68878

I wanted to do this for working in two branches side by side and then I realized it was not possible because you cannot have two active branches in exact same git repo folder.

So, if you are looking to do the same, you should instead just make a copy of a folder and switch to another branch there. Options described in other answers will not work for this scenario due to fundamental way git works.

Upvotes: 2

Joel V98
Joel V98

Reputation: 561

click file > duplicate workspace

Upvotes: 55

Zhiyong Li
Zhiyong Li

Reputation: 519

The accepted answer works, but I don't really like the fact that the folder is opened into an unnamed workspace, and upon closing window, we will be prompted to save that workspace. I am expecting more like Sublime Text like behavior.

Luckily there is VSCodium, VSCode's twin/clone without telemetry to Microsoft. So I ended up opening the folder once in either VSCode or VSCodium, then a second time in the other. This so far worked quite well for me.

Upvotes: 3

Elkhan Dadashov
Elkhan Dadashov

Reputation: 2827

In the latest version, it is actually much simpler. In a window of the project you want to duplicate, open the command panel (Command + Shift + P in Mac or Ctrl + Shift + P in Ubuntu), then type dupl (and select Workspaces: Duplicate As Workspace in New Window), this will duplicate your workspace in a new window. Now you can have 2 windows of the same project at the same time.

Upvotes: 257

Shital Shah
Shital Shah

Reputation: 68878

In addition to accepted answer, here's the trick if you want to open same project in two different windows but showing two different git branches:

Copy the project folder and open that folder!

If you want two windows in two different git branches then this simple trick works. I don't know of any other solutions.

Upvotes: 4

Alexander Kireyev
Alexander Kireyev

Reputation: 10825

Click Add workspace folder... and open the same folder. Works for me, other solution doesn't work, just jump focus to another window.

Upvotes: 9

Maurits Moeys
Maurits Moeys

Reputation: 1250

As far as I know, the accepted answer is not correct as C14L indicates.

It can be done by opening a different folder that includes the folder you're working in. So say we have /project and /project/src and /project/build, you're probably interested in having src open in two instances of VSCode, which you can achieve by opening /project and /project/src.

Upvotes: 5

Related Questions