如何在VS Code命令行中打开远程文件夹?

13

我可以使用code /path/to/folder来启动VS Code并打开一个本地文件夹。是否有可能通过在命令行中指定机器和文件夹来打开远程机器上的文件夹(通过Remote SSH扩展)?


由于这会违反安全规定,所以您不能这样做。 - Khanh Le Tran
这个回答解决了你的问题吗?Vscode (code.exe) 命令行参数通过 SSH 立即打开远程工作区文件夹 - Jacob Stern
2个回答

14

在Linux或Mac终端的CLI中:

code --folder-uri=vscode-remote://ssh-remote+<主机名><绝对路径>

类似这样:

code --folder-uri=vscode-remote://ssh-remote+centos8stream.local/home/guillaume/workspace/


在我的~/.ssh/config文件中,我有:

Host centos8stream.local
    Hostname 10.41.11.69
    User guillaume

在我的终端中,我可以通过ssh centos8stream.local连接到我的服务器。

然后我可以直接打开远程服务器上的vscode:

code --folder-uri=vscode-remote://ssh-remote+centos8stream.local/home/guillaume/workspace/

我甚至在~/.zshrc文件中创建了一个别名函数。

function rcode() { code --folder-uri=vscode-remote://ssh-remote+$1/home/guillaume/$2 }

然后我只需输入: rcode centos8stream.local workspace/my_project

4
这个函数的更清晰版本如下: function rcode() {code --remote ssh-remote+$1 $2}基于 https://dev59.com/XL7pa4cB1Zd3GeqPqg1L - p8me

0

将远程文件夹挂载到您的开发工作站并在VSCode中打开。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接