Vim Tips Wiki
Register
Advertisement

Previous TipNext Tip

Tip: #1003 - Windows file associations

Created: September 25, 2005 19:48 Complexity: basic Author: Associate files with Gvim in Windows Version: 5.7 Karma: 42/23 Imported from: Tip#1003

For example, type in console / cmd.exe (winnt <=)

assoc .php=PHPFile 
ftype PHPFile="C:\Program Files\Vim\Vim63\gvim.exe" --remote "%1" 

Then whenever you double click a .php file in explorer, it will be opened in existing Gvim window (or it will open new Gvim window if there is no already opened Gvim window).

Notes

  • assoc is the command to associate an extension with a filetype in the registry
  • ftype is the command to set the action (program) that will be executed for a specific filetype

Comments

I actually prefere the context menu that the Gvim installer gives you in a Windows install.

  • Edit with Vim
  • Edit with Existing Vim - <file name>

will appear when you right-click on a file in Explorer.

In fact if you have more than one Gvim window open, all of them will appear in the context menu and so you can choose which existing Gvim session to open your file within.

Craig Emery , September 26, 2005 1:10


This also works with Gnome / KDE. And on Mac it's the standard way to open files in Vim.

It's smart to open files "inside" one instance of VIM. All your actions are saved (like yanking, pasting or searching) - and you really don't have to keep the track on the windows (by using mouse or alt+tab). Using a plugin like minibufexpl you can keep track of the buffers open.Another gain is to use multiply desktops - for instance, I have Nautilus on one and VIM on another.

Check out: minibufexpl

amix at amix.dk , September 26, 2005 1:10


Thank you for that helpful tip. But maybe it is better to use --remote-silent instead of --remote. So you will not get a warning dialog, when opening a file, and no gvim is already running.


info--AT--cvjb.de , September 30, 2005 3:58


Associating files with GVIM --remote-silent works pretty well for me, except in the following scenario:

  1. there is a GVIM instance already running.
  2. I select multiple files in File Explorer and hit Enter.

Some of the files that were selected will not be opened, they simply get "lost". It seems to work every time if I just select a single file. It figure it must be some sort of timing issue in the GVIM server.

Has anyone else experienced this and found a workaround?


markcpa-at-pacbell-dot-net , September 30, 2005 11:17


No, sorry. I have tried your scenario, and all selected files opened in the already running instance of gvim.

info--AT--cvjb.de , October 5, 2005 1:30


didn't work for me using cmd

so I tried it from folder options->filetypes instead. I had to restore the changes I made in the shell before entering the advanced dialog. (the restore button changes to the advanced button after you do this)

then:

&Same Vim Window "C:\Program Files\Vim\Vim63\gvim.exe" --remote "%1" (forget the dde fields, they get filled in automatically)

and set as default

if you were doing a log of files it would probably take less time than using cmd since u can use ctrl-v!


Anonymous , October 15, 2005 4:02


Advertisement