History Report a problem
Article Edit this page Discussion

Launch files in new tabs under Windows

From Vim Tips Wiki

(Redirected from VimTip1440)
Jump to: navigation, search
 

[edit] Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1440Previous TipNext Tip

Created: December 14, 2006 Complexity: basic Author: Xu Song Minimum version: n/a Karma: 294/101 Imported from: Tip#1440


Many text editors automatically launch new files in tabs, rather than use a separate window for each new file. Here's how to make Vim behave that way under Microsoft Windows.

[edit] Using File Associations

To automatically open a file in a Vim tab with a double-click or other "Open" action, you need to set up file associations. Open a command prompt window (Start, Run cmd.exe). This example uses C source-code files – modify the commands for whatever file types you want. At command prompt, type (you may need to change the path to suit your system):

ftype code="C:\Program Files\Vim\vim71\gvim.exe" --remote-tab-silent "%1"
assoc .c=code
assoc .h=code

Now, double-clicking on .c or .h files will open them in tabs in a single instance of gvim.

[edit] Using the Windows Send To Menu

Obviously you can't enter file associations for every file you'll ever open in Vim. To provide an "open in tabs" capability for files without an association, you can add an entry to your "Send To" context menu, as follows:

  1. Click Start, Run then type SendTo and press Enter. If the Profile path for your user name has been changed, you may need to run %USERPROFILE%\SendTo rather than just SendTo.
  2. The SendTo directory should now be open. It contains the shortcuts in your Send To context menu. Right-click the SendTo window and add a new shortcut to gvim.
  3. Edit the 'Target' box in the Properties of the gvim shortcut to read (you may need to change this for your path to gvim):
    "C:\Program Files\Vim\vim71\gvim.exe" --remote-tab-silent
    .

In Windows Explorer, right-click one or more files, and select Send To, gvim in the context menu. You can repeat this to open other files in new tabs in the same Vim instance.

[edit] Using different gvim instances for different file types

If wanted, you can define file associations so that certain file types are opened in one instance of gvim, while others are opened in a different instance.

For example, the following will cause .log and .txt files to be opened in an instance of gvim named TXTVIM, while .c and .h files would be opened in another instance using the code example given earlier.

ftype txtfile="C:\Program Files\Vim\vim71\gvim.exe" --servername TXTVIM --remote-tab-silent "%1"
assoc .log=txtfile
assoc .txt=txtfile

SendTo menu items for specific Vim instances can be created in the same way, by adding a --servername option before the --remote-tab-silent in the target for the shortcut created in the section above.

Note that the .txt extension defaults to the txtfile association on Windows. In fact, many extensions are already associated with txtfile, so just setting the ftype as above will automatically set the correct behavior for several filetypes, more of which (such as .log) can be added with assoc as shown.

To see a list of current associations on your system, type assoc with no arguments in a cmd window. Or, for easier viewing, read the list into Vim with
:r !assoc

[edit] See also

[edit] Comments


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Terminator Wiki
Legend of Zelda Wiki
Flash Gordon
Everquest II Wiki
Yo-Yo Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Launch files in new tabs under Windows"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation