I'd like to add a Windows right-click menu entry to quickly open text files in WSL Vim, without manually opening up a terminal. Thanks @romainl.
2 Answers
Create a registry key at
Computer\HKEY_CLASSES_ROOT\*\shell
namedOpen in Vim
, and a subkey for it ascommand
:Computer\HKEY_CLASSES_ROOT\*\shell\Open in Vim
Computer\HKEY_CLASSES_ROOT\*\shell\Open in Vim\command
Edit the string value of the
command\(Default)
asbash.exe -c "wslpath '%1' | xargs nvim"
(alternatively, you can substitute nvim with vim).Download a Vim logo which you can convert online to an
.ico
extension. Create anIcon
string value under theOpen in Vim
key, and edit its value with the path of the.ico
image.
You can see the resulting entry below. Clicking on it would open up a WSL terminal with the selected textfile opened in Vim. Upon exitting Vim, the terminal closes, too.

- 638
- 6
- 12
-
This adds a context menu for all filetypes. Is there a way to add a context menu only for textfiles? – Joe Dec 16 '18 at 14:35
-
[@Joe](https://stackoverflow.com/users/5751969/joe) in that case you wanna go create this key structure and do the above described. For me the the \.txt key was completely empty, so I had to create the shell key, too. `Computer\HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\shell\Open in Vim\command` – davidanderle Jan 26 '19 at 11:11
Add an item to the context menu to open a file in WSL VIM
with PowerShell
:
New-Item -Path 'Registry::HKEY_CLASSES_ROOT\*\shell\VIM\command' -Force | Out-Null;
Set-ItemProperty -Path 'Registry::HKEY_CLASSES_ROOT\`*\shell\VIM' -Name '(default)' -Value 'Open in VIM' -Force | Out-Null;
Set-ItemProperty -Path 'Registry::HKEY_CLASSES_ROOT\`*\shell\VIM' -Name 'Icon' -Value 'C:\Windows\System32\wsl.exe,0' -Force | Out-Null;
Set-ItemProperty -Path 'Registry::HKEY_CLASSES_ROOT\`*\shell\VIM\command' -Name '(default)' -Value "wsl vim -p `"`$(wslpath '%1')`"" -Force | Out-Null;
Or use a registry file as an alternative.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\VIM\command]
@="wsl sudo vim -p \"$(wslpath '%1')\""

- 2,510
- 3
- 22
- 35