I have a shortcut to open vim, but I would like to create a shortcut to open the currently selected file in windows explorer with vim (if that is not the program associated with the file's type).
Using the shortcut for the executable opens it with no file selected.
5 Answers
Create an entry in HKEY_CLASSES_ROOT\*\shell
1. Right-click it and choose new key - Name it "Open with VIM"
2. Right Click the new key - choose new key - and name it "command"
3. Set that key's default value to "PathToVIM" "%1" with quotes
It is a mouse shortcut, instead of keyboard. From then on right clicking on any file with give a "Open with VIM" in its context menu.
Works perfectly well as mentioned on microsoft's site
By design, the Open With menu option is not available when you right-click executable files (.cmd, .bat, .pif, .scf, .exe, .com, or .scr), or shortcuts to executable files.
If you've lost the Open With menu option for ALL file types, including non-executable files, follow this steps:
Click Start, All Programs, Accesories, Notepad.
Copy and paste this text:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT*\shellex\ContextMenuHandlers\Open With] @="{09799AFB-AD67-11d1-ABCD-00C04FC30936}"
Click File, Save As, name the file "OpenWith.reg" (WITH THE QUOTATION MARKS) and click OK.
Now double-click OpenWith.reg, click Continue, Yes, OK, and see if the problem is solved.
Hope it helps.
ideally you should add the & char in the description of the verb that identifies the action you want to trigger. it is in the registry key associated to the application related to the file extension of the selected file (hum.. quite complicated) the char following the & will become your hotkey as stated in the msdn doc here
(of course this link explains how to do it better than I can)
Verbs can also have a display string associated with them, which is displayed on the shortcut menu instead of the verb string itself. For example, the display string for openas is Open With. Like normal menu strings, including an ampersand (&) in the display string allows keyboard selection of the command.
but (at least on windows 10 where I've tried it) it doesn't work for me, or maybe i'm doing something wrong. Unfortunately I don't have a windows 7 on hand so I cannot verify the behavior there
1I'd do it with an AutoHotkey script like so:
SendMode Input
#SingleInstance force
^+V::
If WinActive("ahk_class CabinetWClass") or WinActive("ahk_class Progman") ; explorer or desktop
{ Clipboard = Send ^c ClipWait Run, gvim %clipboard%
}
returnThis script does the following
- Triggers when "Ctrl Shift v" is pressed
- Copies the selected file path (among other things) to clipboard like pressing "ctrl c"
- Runs gvim with the copied file path as an argument
You may need the full path instead of "gvim." It works on mine because gvim is on my Windows path. See this question for more on vim and system path:
Here's the gist.
To be complete, you should force #SingleInstance and back up and restore the clipboard contents and a few other things but .. I'll leave that "as an exercise for the reader." =P
- Right-clock the file you want to open with VIM
- Select "Open with"
- Select "Choose default program..."
- Browse to the VIM executable location
- Make sure "Always used the selected program to open this kind of file" is checked
- Click OK
From now on, this file type will be opened by VIM.
3