问题描述
我想要一种使用相同的VS Code窗口从终端打开/创建文件的方法。
如果我尝试使用终端发出以下命令,它将关闭当前窗口并打开一个新窗口。
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
(它们似乎都在做相同的事情)以不覆盖您当前的工作空间。