【问题标题】:VS Code - open a file using the same window and keeping the workspaceVS Code - 使用同一窗口打开文件并保留工作区
【发布时间】:2020-12-04 13:35:35
【问题描述】:

我想要一种从终端打开/创建文件的方法 - 使用相同的 VS 代码窗口。

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

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

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

如果我只使用..

code . nomeofthefile.js 
  • 这将打开一个新窗口。这也不是我想要的。

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

【问题讨论】:

    标签: reactjs visual-studio-code vscode-settings


    【解决方案1】:

    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(它们似乎都在做同样的事情)以不覆盖您当前的工作区。

    【讨论】:

    • omg.... 只需删除“。”非常喜欢!!!!
    猜你喜欢
    • 2018-12-20
    • 2019-08-17
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 2023-01-11
    相关资源
    最近更新 更多