5

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.

1

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.

| improve this answer | |
1

Works perfectly well as mentioned on microsoft's site https://answers.microsoft.com/en-us/windows/forum/windows_vista-desktop/right-click-open-with-command-missing-help-please/a9c3f139-075c-4285-b87d-25e899fb8b27

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:

  1. Click Start, All Programs, Accesories, Notepad.

  2. Copy and paste this text:

  3. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT*\shellex\ContextMenuHandlers\Open With] @="{09799AFB-AD67-11d1-ABCD-00C04FC30936}"

  4. Click File, Save As, name the file "OpenWith.reg" (WITH THE QUOTATION MARKS) and click OK.

  5. Now double-click OpenWith.reg, click Continue, Yes, OK, and see if the problem is solved.

Hope it helps.

| improve this answer | |
0

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

https://msdn.microsoft.com/en-us/library/windows/desktop/cc144101(v=vs.85).aspx

(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

| improve this answer | |
0

I'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%
}
return

This 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: https://stackoverflow.com/q/17632102/2043621

Here's the gist: https://gist.github.com/OkumaTony/b0ce35e6a72e33787c869457513472fe

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

| improve this answer | |
-1
  1. Right-clock the file you want to open with VIM
  2. Select "Open with"
  3. Select "Choose default program..."
  4. Browse to the VIM executable location
  5. Make sure "Always used the selected program to open this kind of file" is checked
  6. Click OK

From now on, this file type will be opened by VIM.

| improve this answer | |
  • I don't want vim to become the new default for that file type. I just want to make it easier to open the file type with vim. For instance, I want html files to default to a browser, but I shouldn't have to search through the menus for the "open with" every time I want to open it with an editor. – DanB Aug 15 '11 at 4:41
  • Then set is as the default HTML editor in your default browser (look for instructions o how to set default applications for your preferred browser) – Traveling Tech Guy Aug 15 '11 at 5:34
  • My goal is to open any file in my editor of choice (which happens to be VIM) with a keystroke-combination. I only gave html as an example, but I don't understand how setting my editor in the browser achieves that goal even for html files. – DanB Aug 15 '11 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.