Linux下手动注册vscode:协议,实现通过链接打开VS Code
手动注册vscode:协议的方法
根据你使用的操作系统,按照以下步骤手动注册vscode:协议:
Linux系统
- 创建/修改VS Code桌面文件
- 打开终端,创建或编辑VS Code的desktop文件:
nano ~/.local/share/applications/code.desktop - 在文件中添加或更新以下内容(替换
/path/to/your/code为你tarball解压后的VS Code可执行文件路径):[Desktop Entry] Name=Visual Studio Code Comment=Code Editing. Redefined. Exec=/path/to/your/code/code --open-url %u Icon=/path/to/your/code/resources/app/resources/linux/code.png Type=Application Terminal=false Categories=Development;IDE; MimeType=x-scheme-handler/vscode;
- 打开终端,创建或编辑VS Code的desktop文件:
- 更新桌面数据库
运行命令使修改生效:update-desktop-database ~/.local/share/applications/ - 绑定协议处理程序
执行命令将vscode:协议关联到VS Code:xdg-mime default code.desktop x-scheme-handler/vscode
macOS系统
- 添加协议关联
打开终端,运行以下命令(确保VS Code已解压到应用目录,例如/Applications/Visual Studio Code.app):defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType = "x-scheme-handler/vscode"; LSHandlerRoleAll = "com.microsoft.VSCode";}' - 刷新LaunchServices缓存
执行命令使修改立即生效:
重启Firefox后即可测试跳转功能。/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
Windows系统
- 创建注册表导入文件
新建文本文件并命名为vscode-protocol.reg,填入以下内容(替换C:\path\to\Code.exe为你tarball解压后的VS Code可执行文件路径):Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\vscode] @="URL:vscode Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\vscode\shell] @="" [HKEY_CLASSES_ROOT\vscode\shell\open] @="" [HKEY_CLASSES_ROOT\vscode\shell\open\command] @="\"C:\\path\\to\\Code.exe\" --open-url \"%1\"" - 导入注册表
双击该vscode-protocol.reg文件,确认导入注册表即可。完成后重启Firefox测试跳转。
内容的提问来源于stack exchange,提问作者Robin Green
相关产品推荐
相关产品推荐

