created July 9, 2002 · complexity intermediate · author jcline · version 5.7
I find myself installing the following registry modification for all my PCs now (even other people's PCs). It applies to Microsoft Windows machines only. The following is also for Windows 9x. NT or XP or 2000 may require modifications (which I don't care to understand!).
The problem: You double-click on a file that doesn't have a registered type and that pesky "What program should I use?" dialog pops up. Even worse, depending on the installation, the GVim icon may not be listed, and one has to browse to the executable. and then the type becomes forever bonded to being editted with GVim (if that box is checked). The standard Vim 6.1 installation does include a "right click to edit" menu item for all files, but a double-click is so much faster!
The solution: What if unregistered types would just automatically open up in GVim? Well, they can. with a little registry trickery.
How to Install it
Step 1. Create a text file called "vimalways.reg" and paste the below text into it.
REGEDIT4 [HKEY_CLASSES_ROOT\Unknown\shell] @="vim" [HKEY_CLASSES_ROOT\Unknown\shell\vim] [HKEY_CLASSES_ROOT\Unknown\shell\vim\command] @="\"C:\\Vim\\vim61\\gvim.exe\" \"%1\""
Step 2. Important NOTE: You will have to edit the pathname to correspond to the pathname of your GVim.exe. The text below works fine for a GVim 6.1 default installation.
Step 3: Save the file.
Step 4: Right-click on the file and select "install". Then you are done!
Note 1. This can't be de-installed automatically, and if you want to remove it, you'll have to edit the registry by hand (annoying, but easy).
Note 2. Keep this file around, so when you upgrade your GVim, all you have to do is modify the pathname (to say, for example, vim62) and then install it again.
Note 3. If you want to open all files without file-extension in GVim by default, paste this text instead:
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.] [HKEY_CLASSES_ROOT\.\shell] [HKEY_CLASSES_ROOT\.\shell\open] [HKEY_CLASSES_ROOT\.\shell\open\command] @="\"C:\\Vim\\vim61\\gvim.exe\" \"%1\""
- MS Windows 95 - works OK
- MS Windows 98 - works OK
- MS Windows NT - not sure; if anyone can confirm this please add a note.
- MS Windows 2000 - works OK
- MS Windows XP - should work.
- MS Windows 7 - works, with data added manually in regedit (change existing ...\shell key value from "openas" to "vim")
What I do on any machine I'm working on, and should work in any of the Windows OSs, is add a shortcut to Gvim in my SendTo folder. This can be done by:
- Right-click on the START button.
- Click Explore All Users
- Find the folder with your username and open it.
- Find the Send To folder, and copy a shortcut to Gvim in there.
Now, if I right-click on any file, I can choose to send it to GVim by using the Gvim short-cut on the Send-to list.
The above instructions maybe impossible to perform if you have insufficient privileges. In that case, it appears that HKEY_CLASSES_ROOT can be replaced by
(This works for me on win2k)
I had a MERGE option when right clicking on the .reg file. I also couldn't get it to import until I added the top line below. Thought I'd share the modification I had to make. Thanks for the tip.
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Unknown\shell] @="vim" [HKEY_CURRENT_USER\Unknown\shell\vim] [HKEY_CURRENT_USER\Unknown\shell\vim\command] @="\"C:\\Program Files\\Vim\\vim70\\gvim.exe\" \"%1\""
To set Vim as the editor for a specific file type on Windows XP:
Windows Explorer tools folder options file types select a type, for example HTML click ADVANCED button (if it is visible) select Edit action on left, and click EDIT button on right click Browse ... button, and then select Vim click OK a few times
Search your C: drive for wscript.exe and either delete it or (possibly) rename it. (Don't know if renaming it works.) A reboot may be required.
On my system, though, I couldn't find it, but adding this line to the above registry file did the trick:
Note that this deletes that key. You might need to reassociate .js. Also, if you're trying to edit .js files on a network drive and are getting warnings, follow instructions here: http://windowsxp.mvps.org/networkfile.htm. In that case, I also had to click Advanced (for the first option) and add my network drive letter (ie F:), which automatically added file://192.168.1.10 to my list.
- Windows Script Host can be very useful. I certainly would never recommend something as drastic as renaming the system file wscript.exe to disable scripting in Windows. If you're worried about viruses, just don't run .js or .vbs files from unknown sources without examining them in an editor first. Even hijacking the "Open" function is questionable, it makes it more difficult to run a script from the Windows command-line.