Skip to content
Browse files

Version 7

Fixed problem where new Tab + Split options were oopening files on more than one tab if you passed more than about five filenames.
  • Loading branch information...
1 parent 5fb7fb6 commit 5c30cdae2a456b2b326c5a01b00e3b7ef93f229f Geoff Wood committed with May 10, 2013
Showing with 15 additions and 7 deletions.
  1. +5 −1 doc/gvimt_README.txt
  2. +10 −6 gvimt.bat
View
6 doc/gvimt_README.txt
@@ -4,6 +4,8 @@ gw 13/9/12 - Created
gw 25/9/12 - Updated to raise Vim to foreground, removes awk and grep dependency, adds path option to specify vim location
gw 9/10/12 - Goes to normal mode first to make sure commands execute and don't just go into the file. Waits a bit when starting vim. Clears the command from the command line afterwards.
gw 9/5/13 adds tv and ts modes to open groups on new tab
+gw 10/5/13 added tabsplit_wait_s to fix problem where opening many files would end up on more than one tab
+
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.
@@ -19,7 +21,9 @@ 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 your gvim typically takes longer than a second to start up, change "set vim_startup_time_ms" to be more milliseconds.
+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 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.
View
16 gvimt.bat
@@ -13,6 +13,7 @@ REM gw 27/9/12 expand to full path so can call from command line for a file in t
REM also fixed typo recently introduced where vsplits were just acting as splits
REM gw 8/10/12 get into normal mode first, fixes problem where command appears in file text in insert mode
REM gw 9/5/13 adds tv and ts modes to open groups on new tab
+REM gw 10/5/13 added tabsplit_wait_s to fix problem where opening many files would end up on more than one tab
setlocal ENABLEDELAYEDEXPANSION
@@ -24,6 +25,7 @@ set vim_path=
set batch_path="c:\batch files"
set already_ran=false
set vim_startup_time_ms=1000
+set tabsplit_wait_s=3
if %1_==_ goto usage
if /i %1 NEQ t if /i %1 NEQ v if /i %1 NEQ s if /i %1 NEQ tv if /i %1 NEQ ts goto usage
@@ -52,8 +54,6 @@ REM is running, the rest to wait for this
:check_already_running
set already_running=false
if exist %short_batch_path%\gvimt.tmp (
- if /i %task% EQU tv set task=v
- if /i %task% EQU ts set task=s
set already_running=true
set already_ran=true
ping -w 100 -n 1 1.2.3.4
@@ -72,7 +72,7 @@ REM Otherwise do it now
if %already_ran%==false (
tasklist | findstr gvim.exe > nul
if not !errorlevel!==0 (
- start %vim_path%gvim.exe %1
+ start %vim_path%gvim.exe -c "let g:gvimt_time_this=localtime()" %1
set already_ran=true
REM sometimes we miss the first file out possibly if vim hasn't finished starting?
@@ -87,12 +87,16 @@ if %already_ran%==false (
REM if %1_==_ goto raise_to_foreground
if %1_==_ goto end
-if /i %task% GEQ t if /i %task% LSS u start %vim_path%gvim.exe --remote-send "<Esc>:tablast | tabe %~f1<CR>:call foreground()<CR><CR>"
+if /i %task% EQU t start %vim_path%gvim.exe --remote-send "<Esc>:tablast | tabe %~f1<CR>:call foreground()<CR><CR>"
if /i %task% EQU v start %vim_path%gvim.exe --remote-send "<Esc>:vsplit %~f1<CR>:call foreground()<CR><CR>"
if /i %task% EQU s start %vim_path%gvim.exe --remote-send "<Esc>:split %~f1<CR>:call foreground()<CR><CR>"
+
+if /i %task% EQU tv start %vim_path% gvim.exe --remote-send "<Esc>:if exists("""g:gvimt_time_this""") | let g:gvimt_time_last=g:gvimt_time_this | else | let g:gvimt_time_last=0 | endif | let g:gvimt_time_this=localtime() | if g:gvimt_time_this > g:gvimt_time_last + %tabsplit_wait_s% | tablast | tabe %~f1 | else | vsplit %~f1 | endif | call foreground()<CR><CR>"
+
+if /i %task% EQU ts start %vim_path% gvim.exe --remote-send "<Esc>:if exists("""g:gvimt_time_this""") | let g:gvimt_time_last=g:gvimt_time_this | else | let g:gvimt_time_last=0 | endif | let g:gvimt_time_this=localtime() | if g:gvimt_time_this > g:gvimt_time_last + %tabsplit_wait_s% | tablast | tabe %~f1 | else | split %~f1 | endif | call foreground()<CR><CR>"
+
shift
-if /i %task% EQU tv set task=v
-if /i %task% EQU ts set task=s
+
goto next_file
REM This routine sort of works but its very complicated and it throws errors sometimes

0 comments on commit 5c30cda

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