sponsor Vim development Vim logo Vim Book Ad

gvimt : Open new files in gvim in new tabs, splits or vertical splits

 script karma  Rating 26/10, Downloaded by 5417  Comments, bugs, improvements  Vim wiki

created by
Geoff Wood
 
script type
utility
 
description
gvimt.bat is a script for Windows to open new files in gvim in new tabs, splits or vertical splits.  It starts gvim if it is not running already.

Call it from SendTo menu, from Context menu entries or from the command line.

It ignores command line vim, and gvims where the --servername parameter has changed the name to not include "GVIM"

It prefers to use vim.exe (command line vim, not gvim) to check if gvim is already running.  If that's not available it will use the tasklist command (which exists from Windows XP, but not in Windows 2000).  On Windows 2000 you'll need to have an instance of gvim running already.  Tasklist is not always reliable when using several remote desktop sessions on a machine (because for some reason %SESSIONNAME% parameter is not always populated in the batch file's environment).

It creates gvimt.tmp while it is running, if it crashes or goes wrong for some reason, delete this file.

Why use this instead of simpler methods?
========================================
There are simpler ways to call gvim directly passing file names to new tabs.  There is the --remote-tab parameter, for example.  Some methods are discussed here: http://vim.wikia.com/wiki/Launch_files_in_new_tabs_under_Windows

There are some problems doing this with many files from the Windows context menu:
- There is no --remote-split parameter so a different approach is needed for opening files in a new split window.  --remote-send can be used to send an arbitary command for this, but unlike --remote-tab it will not open a new instance of gvim if one doesn't already exist.
- If you select multiple files and use the Windows context menu, each file gets its own invocation of the command.  gvim does not handle several simultaneous --remote-tab commands well.
- The SendTo menu does pass all the selected files to one command, but it is an extra click on the right menu to get there, so it is nice to use the Context menu.
 
install details
Create directory C:\Batch Files\ and extract the package there. (If you want another directory, change "set batch_path=" at the start of gvimt.bat, and modify gvim.reg accordingly.)

If you do not have vim.exe, and do not have the tasklist command (e.g. using Windows 2000), edit the batch file and change "set already_ran" to "=true" at the start of gvimt.bat.

If your gvim typically takes longer than a second to start up, change "set vim_startup_time_ms" to be more milliseconds.

If you find tv and ts commands open files on more than one tab, change "set tabsplit_wait_s" to be more seconds.

If gvim.exe or vim.exe are not in your path, edit gvimt.bat and change "set gvim_path=" and "set vim_path=" at the start.  Paths should end with \ and be quoted, e.g.

    set vim_path="c:\program files\vim\vim73\"
    set gvim_path="c:\program files\vim\vim73\"

Optionally run the gvimt.reg file to create Context Menu entries.

Optionally, create shortcuts in your SendTo directory with these targets:
"c:\batch files\gvimt.bat" t
"c:\batch files\gvimt.bat" v
"c:\batch files\gvimt.bat" s
"c:\batch files\gvimt.bat" tv
"c:\batch files\gvimt.bat" ts

Name these three shortcuts something like "Edit with Vim Tab", "Edit with Vim VSplit", "Edit with Vim Split", "Edit with Vim VSplit Tab", and "Edit with Vim Split Tab"

Your SendTo menu directory location depends on which version of Windows you are using.  Under XP it is probably c:\documents and settings\username\SendTo.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
gvimt.zip 10 2014-03-26 7.0 Geoff Wood Stop using short paths to be Windows 7 compatible
gvimt.zip 9 2013-12-05 7.0 Geoff Wood gw 2/12/13 Prefer to use cmd-line vim to list remote servers. If it does have to use tasklist, handle case where sessionname is not populated (by failing more nicely)
gvimt.zip 8 2013-06-17 7.0 Geoff Wood Fixed so only considers if vim is already running in this user session, to avoid failure when another user is running vim
gvimt.zip 7 2013-05-10 7.0 Geoff Wood Fixed problem where new Tab + Split options were oopening files on more than one tab if you passed more than about five filenames.
gvimt.zip 6 2013-05-09 7.0 Geoff Wood Added tv and ts so you can open a new single tab with a split view of several files
gvimt.zip 5 2012-10-09 7.0 Geoff Wood Goes to normal mode first to make sure commands execute and don't just go into the file being edited.
Waits a bit when starting vim.
Clears the command from the command line afterwards.
gvimt.zip 4 2012-09-27 7.0 Geoff Wood Expand passed filename to full path so can call from command line for a file in the local directory, as well.

Also fixed typo recently introduced where vsplits were just acting as splits

gvimt.zip 3 2012-09-25 7.0 Geoff Wood Removed dependency on awk and grep
Added vim_path option in case gvim.exe is not in your path
gvimt.zip 2 2012-09-25 7.0 Geoff Wood Added command to raise Vim to foreground

Updated install instructions to mention changing gvim.reg if you change the path from C:\Batch Files\
gvimt.zip 1 2012-09-13 7.0 Geoff Wood Initial upload
ip used for rating: 18.220.160.216

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github