有许多潜在原因可能会阻止 VSCode 远程 ssh 集成终端通过“code”命令打开文件。
快速解决:
要让 vs-code 远程打开,请尝试在 .bashrc 中添加此行
alias code="${HOME}/.vscode-server/bin/$(ls -t1 ${HOME}/.vscode-server/bin | head -n 1)/bin/remote-cli/code"
现在您可以使用打开文件code -r filename.txt
在集成终端中打开文件。
The -r
参数重新使用当前窗口。
更详细的解释:
从远程主机上的集成 VS-Code 终端:
# run this and verify the current user, show the .sock file and permissions are ok.
echo $VSCODE_IPC_HOOK_CLI
# also check path and make sure you've got some entry to ~/.vscode-server should appear:
echo $PATH
我不完全确定集成终端设置 .vscode-server 路径的最佳/正确方法。
我认为这与terminal.defaultProfile
设置,但我不是 100%,可能只是在我的内部预览中被破坏。
但是我 100% 确定如果 ~/.vscode-server/bin/*/bin/remote-cli 没有出现在它将无法工作的路径中,您可以尝试添加它:
export PATH=$PATH:"~/.vscode-server/bin/**/bin/remote-cli"
然后命令code -r filename.txt
将在集成编辑器中打开文件,但是我认为快速修复中的别名解决方案更容易/更好。