今天微软发布了Visual Studio Code文件/文件夹编辑器。

第一个限制是它似乎是一个单实例应用程序。

是否有一种方法可以获得多个实例,或者让它同时打开多个文件夹?


当前回答

我最简单的技巧是复制你的工作空间使用的.code-workspace文件,你基本上可以欺骗VSCode有两个独立的窗口。

不过,如果您想同步设置,则必须同步两个文件。在Windows 10/11中,你可以使用提升的命令提示符(不是Powershell),并使用mklink /H link Target创建一个硬链接。

我尝试使用符号链接,但它只是试图重新打开目标。通过硬链接,您可以修改工作区设置并使它们同步!

其他回答

Use

code -n

启动程序时。这将“打开Visual Studio Code的新会话,而不是恢复前一个会话”。(从这儿)。

我使用它的方式是修改我的“Code”快捷方式,包括-n参数:

如果不行,重新启动VSCode

如果你使用VS Code用于多种目的(c#, Python,数据库客户端等),用不同的颜色和主题在任务栏中分离每个实例是很有用的。

要做到这一点,你可以结合使用这些技巧:

For having separated icons in taskbar follow these steps (taken from https://www.reddit.com/r/vscode/comments/fkplzc/how_do_i_prevent_vscode_portable_copies_from/fkulriu?utm_source=share&utm_medium=web2x&context=3): Download portable version from https://code.visualstudio.com/docs/editor/portable (go to download page link and get proper '.zip' file), extract it somewhere and create a folder named 'data' in it (beside code.exe) to enable portable mode. Open directory {vscode_installation_dir}/resources/app Edit the file product.json with a text editor (VS Code/Notepad.exe/Notepad++ or whatever) Locate the key win32AppUserModelId Change its value to what you want it to be, and save the file: Now, if you run the executable, this modified copy of VS Code should remain separate from other VS Codes in the Windows Taskbar. For changing the VS Code theme color itself use Peacock (https://marketplace.visualstudio.com/items?itemName=johnpapa.vscode-peacock) For changing taskbar icon you can use https://github.com/electron/rcedit (sample use: https://www.reddit.com/r/vscode/comments/fkplzc/how_do_i_prevent_vscode_portable_copies_from/fky786v?utm_source=share&utm_medium=web2x&context=3) By pining the icons to the taskbar you can use shortcut of (Win key + Numbers) to easily open and switch between them.

最终结果:

如果你把所有的JavaScript文件放在一个文件夹下的多个文件夹中,效果很好,这就是我所做的:

您可以打开多个窗口(通过菜单或再次运行可执行代码)。

然而,不幸的是,目前似乎没有办法实际拥有单独的实例。例如,如果打开了两个shell,每个shell中都有不同的环境(不同的路径等),为两个shell启动代码将导致第二个窗口与第一个窗口共享相同的路径,并忽略启动它的环境。

在Linux上,你可以使用——user-data-dir参数来运行它 我使用的是VSCodium版本,因此它有一个不同的名称,但它也应该适用于标准版本

我从~/复制了配置。在VSCodium2文件夹下 现在可以运行第二个codium实例:

——user-data-dir ~/.config/VSCodium2

我还创建了一个新的.desktop文件:/usr/share/applications/VSCodium2.desktop 在那里,我必须改变Name和Exec属性来启动VSCodium2

有了这些设置,我可以用我的启动器运行多个实例

除了.desktop文件和位置之外,所有这些都应该适用于Windows和Mac