Browse files

Version 3

Removed dependency on awk and grep
Added vim_path option in case gvim.exe is not in your path
  • Loading branch information...
1 parent 3c6e982 commit 2fb999a3b4b95ba81ed844c06e1e2b04df2490db Geoff Wood committed with Sep 25, 2012
Showing with 16 additions and 21 deletions.
  1. +5 −9 doc/gvimt_README.txt
  2. +0 −8 gvimt.awk
  3. +11 −4 gvimt.bat
14 doc/gvimt_README.txt
@@ -1,14 +1,12 @@
Written by Geoff Wood (geoffrey.wood at_symbol
gw 13/9/12 - created
-gw 25/9/12 - updated to raise Vim to foreground
+gw 25/9/12 - updated to raise Vim to foreground, removes awk and grep dependency, adds path option to specify vim location
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 needs grep and awk in the path (tested with gnu versions). Also gvim.exe.
It uses the tasklist command (which exists from Windows XP, but not in Windows 2000) when checking if gvim is already running. On Windows 2000 you'll need to have an instance of gvim running already.
It creates gvimt.tmp while it is running, if it crashes or goes wrong for some reason, delete this file.
@@ -19,6 +17,10 @@ Create directory C:\Batch Files\ and extract the package there. (If you want ano
If you 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 gvim.exe is not in your path, edit gvimt.bat and change "set vim_path=" at the start. Paths should end with \ and be quoted, e.g.
+ set vim_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:
@@ -39,9 +41,3 @@ 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.
-Why use awk, tasklist and grep?
-Calling vim directly from a batch file has problems with backslashes in the target file path vanishing. The simplest approach is just to use something else to call gvim that doesn't mangle the path, I use awk for this sort of thing.
-grepping the tasklist is an easy way to see if gvim is already running.
8 gvimt.awk
@@ -1,8 +0,0 @@
- if (ARGV[1]=="t")
- system("start gvim --remote-send \":tablast | tabe " ARGV[2] "<CR>:call foreground()<CR>\"")
- else if (ARGV[1]=="v")
- system("start gvim --remote-send \":vsplit " ARGV[2] "<CR>:call foreground()<CR>\"")
- else if (ARGV[1]=="s")
- system("start gvim --remote-send \":split " ARGV[2] "<CR>:call foreground()<CR>\"");
15 gvimt.bat
@@ -8,9 +8,15 @@ REM Geoff Wood (
REM gw 13/9/12 created
REM gw 17/9/12 awk script brings vim to the foreground
+REM gw 25/9/12 uses findstr instead of grep, and direct call instead of via awk, and optional vim path added
+REM If gvim.exe is not in your path you can add the path here,
+REM make sure it ends in a \ character and is quoted if necessary
+REM e.g. set vim_path="c:\program files\vim\vim73\"
+set vim_path=
set batch_path="c:\batch files"
set already_ran=false
@@ -50,17 +56,18 @@ REM If another instance ran, it made sure
REM gvim was running
REM Otherwise do it now
if %already_ran%==false (
- tasklist | grep -q gvim.exe
+ tasklist | findstr gvim.exe > nul
if not !errorlevel!==0 (
- start gvim.exe %1
+ start %vim_path%gvim.exe %1
if %1_==_ goto end
-REM run with awk script to avoid issues with \ quoting
-awk -f %batch_path%\gvimt.awk %task% %1
+if /i %task% EQU t start %vim_path%gvim.exe --remote-send ":tablast | tabe %~1<CR>:call foreground()<CR>"
+if /i %task% EQU v start %vim_path%gvim.exe --remote-send ":split %~1<CR>:call foreground()<CR>"
+if /i %task% EQU s start %vim_path%gvim.exe --remote-send ":split %~1<CR>:call foreground()<CR>"
goto next_file

0 comments on commit 2fb999a

Please sign in to comment.