Skip to content
Browse files

Version 2

Added command to raise Vim to foreground

Updated install instructions to mention changing gvim.reg if you change the path from C:\Batch Files\
  • Loading branch information...
1 parent 6083735 commit 3c6e982399c73dfeff88f5f482033c78fe899757 Geoff Wood committed with
Showing with 12 additions and 29 deletions.
  1. +2 −16 README
  2. +3 −2 doc/gvimt_README.txt
  3. +3 −3 gvimt.awk
  4. +4 −8 gvimt.bat
View
18 README
@@ -1,32 +1,18 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=4214
-gvimt.bat
-Written by Geoff Wood (geoffrey.wood at_symbol thomsonreuters.com)
-gw 13/9/12 - created
-
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 gvim.exe, grep and awk in the path (tested with gnu versions).
-
-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\\&#039ll need to have an instance of gvim running already.
+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.
-
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\\&#039t already exist.
+- 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\\&#039t 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.
-
View
5 doc/gvimt_README.txt
@@ -1,6 +1,7 @@
gvimt.bat
-Written by Geoff Wood (geoffrey.wood@thomsonreuters.com)
+Written by Geoff Wood (geoffrey.wood at_symbol thomsonreuters.com)
gw 13/9/12 - created
+gw 25/9/12 - updated to raise Vim to foreground
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.
@@ -14,7 +15,7 @@ It creates gvimt.tmp while it is running, if it crashes or goes wrong for some r
Install instructions:
=====================
-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.)
+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 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.
View
6 gvimt.awk
@@ -1,8 +1,8 @@
BEGIN {
if (ARGV[1]=="t")
- system("start gvim --remote-send \":tablast | tabe " ARGV[2] "<CR>\"")
+ 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>\"")
+ 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>\"");
+ system("start gvim --remote-send \":split " ARGV[2] "<CR>:call foreground()<CR>\"");
}
View
12 gvimt.bat
@@ -1,17 +1,13 @@
@echo off
-REM Script for Windows to open new files in gvim in new tabs,
-REM splits or vertical splits
-REM Starts gvim if not running already
-REM Call from SendTo menu or from Context menu entries
-REM Needs grep and awk in the path
-REM Needs tasklist command (so XP, not Windows 2000)
-REM Creates gvimt.tmp while it is running, if it crashes
-REM for some reason, delete this file
+REM Script for Windows to open new files in gvim in new tabs, splits or vertical splits
+REM See gvimt_README.txt for details
+REM Creates gvimt.tmp while it is running, if it crashes for some reason, delete this file
REM Geoff Wood (geoffrey.wood@thomsonreuters.com)
REM gw 13/9/12 created
+REM gw 17/9/12 awk script brings vim to the foreground
setlocal ENABLEDELAYEDEXPANSION

0 comments on commit 3c6e982

Please sign in to comment.
Something went wrong with that request. Please try again.