VS Code - 使用相同的 window 打开文件并保留工作区

VS Code - open a file using the same window and keeping the workspace

我想要一种从终端 open/create 文件的方法 - 使用相同的 VS 代码 Window。

如果我尝试使用终端发出以下命令,它会关闭当前的 window 并打开一个新的。

code . nameofthefile.js -r --reuse-window

然后,如果我是 运行 npm start - 之前的命令将终止它。最重要的是 - 它会重新加载我的工作区,删除左侧栏中资源管理器中的所有文件夹。

如果我只使用..

code . nomeofthefile.js 

是否可以在 VS Code 中使用终端命令打开一个新文件而不关闭当前文件?

VSCode 命令行 (code) 能够根据您提供的路径打开文件夹和文件。如果您提供多个路径,它将打开所有路径。如果路径不存在,它将在该位置为您创建一个新文件。

# open current folder as workspace
code .

# open file.js in the last used workspace
code file.js # or
code -r file.js

# open file.js inside current folder as workspace
code . file.js

因此,根据您提供的示例,您需要运行 code nameofthefile.js
code -r nameofthefile.js(它们似乎做同样的事情)不覆盖您当前的工作区。

在当前 vs code window 中打开文件夹,同时使用 vs code 终端更改目录:- code -r .