如何通过右键单击打开 VSCode 远程 WSL



我想通过从Windows文件资源管理器右键单击打开VSCode Remote-WSL上的当前文件夹。 我该怎么做? 提前谢谢你。

若要为目录添加 Windows 上下文菜单以在远程 WSL 的 Visual Studio Code 中打开它,请以管理员身份添加以下 Windows 注册表项:

reg add "HKEY_CLASSES_ROOTDirectoryshellWSLVSCodecommand" /t REG_EXPAND_SZ /d "wsl.exe code `wslpath '%1'`"
reg add "HKEY_CLASSES_ROOTDirectoryshellWSLVSCode" /t REG_EXPAND_SZ /d "Open in WSL VSCode"
reg add "HKEY_CLASSES_ROOTDirectoryshellWSLVSCode" /v Icon /t REG_EXPAND_SZ /d "C:UsersUserAppDataLocalProgramsMicrosoft VS CodeCode.exe"

更新图标文件的正确路径。

试试这个'在 WSL 中打开文件夹':
制作注册表文件 (.reg(,粘贴代码并运行:

Windows 注册表编辑器版本 5.00

;删除旧条目 [-HKEY_CLASSES_ROOT\目录\外壳\VSCode] [-HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode]

;添加子菜单以右键单击文件夹 [HKEY_CLASSES_ROOT\Directory\shell\VSCode] "MUIVerb"="Visual Studio Code" "ExtendedSubCommandKey"="Directory\ContextMenus\VSCode" "icon"="C:\Program Files\Microsoft VS Code\Code.exe">

;添加子菜单以右键单击背景 [HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode] "MUIVerb"="Visual Studio Code" "ExtendedSubCommandKey"="Directory\ContextMenus\VSCode" "icon"="C:\Program Files\Microsoft VS Code\Code.exe">

[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode]

[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell]

;设置文本和图标 [HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\open] "MUIVerb"="打开文件夹" "图标"="C:\Program Files\Microsoft VS 代码\代码.exe">

[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\openwsl] "MUIVerb"="在 WSL 中打开文件夹" "图标"="C:\Program Files\Microsoft VS 代码\代码.exe">

;设置命令 [HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\open\command] @="C:\Program Files\Microsoft VS Code\Code.exe" "%V">

[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\openwsl\command] @="wsl.exe --cd "%V" code ." ;这将打开当前文件夹 WSL 端,然后从那里运行代码

结果:示例图像

从: https://gist.github.com/mbartelsm/be2a8ea761e5358cd04e3777d107b186#file-vscode_context-reg

对于"在 WSL 中使用代码打开"(在 WSL 中打开文件(:
创建一个注册表文件 (.reg(,粘贴代码并运行:

Windows 注册表编辑器版本 5.00

[HKEY_CLASSES_ROOT*\shell\VSCodeWsl] @="Open w&ith Code in WSL" "icon"="C:\Program Files\Microsoft VS Code\Code.exe">

[HKEY_CLASSES_ROOT*\shell\VSCodeWsl\command] @="wsl.exe code "$(wslpath '%1'(">

结果:在 WSL 中打开代码示例

从: https://github.com/matuszykrafa/open-with-code-in-wsl

将文件夹的"打开与代码 (WSL( "和"使用代码打开"(WSL( 用于文件。

感谢@Mogzol解决弹出窗口。

Windows Registry Editor Version 5.00
; You may replace
; C:\Program Files\Microsoft VS Code\Code.exe
; with 
; C:\Users\Your User Name\AppData\Local\Programs\Microsoft VS Code\Code.exe
; for correct VS Code icon

; Add the option for right-click on a folder
[HKEY_CLASSES_ROOTDirectoryshellVSCodeWSL]
@="Open with Code (WSL)"
"Icon"="C:\Program Files\Microsoft VS Code\Code.exe"
[HKEY_CLASSES_ROOTDirectoryshellVSCodeWSLcommand]
@="mshta vbscript:Execute("CreateObject(""Wscript.Shell"").Run(""wsl.exe code """"$(wslpath '%V')"""""", 0, False)(window.close)")"

; Add the option for right-click in the background of current folder
[HKEY_CLASSES_ROOTDirectoryBackgroundshellVSCodeWSL]
@="Open with Code (WSL)"
"Icon"="C:\Program Files\Microsoft VS Code\Code.exe"
[HKEY_CLASSES_ROOTDirectoryBackgroundshellVSCodeWSLcommand]
@="mshta vbscript:Execute("CreateObject(""Wscript.Shell"").Run(""wsl.exe code """"$(wslpath '%V')"""""", 0, False)(window.close)")"

; Add the option for right-click on a file
[HKEY_CLASSES_ROOT*shellVSCodeWSL]
@="Open with Code (WSL)"
"Icon"="C:\Program Files\Microsoft VS Code\Code.exe"
[HKEY_CLASSES_ROOT*shellVSCodeWSLcommand]
@="mshta vbscript:Execute("CreateObject(""Wscript.Shell"").Run(""wsl.exe code """"$(wslpath '%1')"""""", 0, False)(window. Close)")"

最新更新