Batch script to open a file in a running instance of gVim

To open a file in a gVim (graphical Vim) instance that is already running, the following command is used.

C:\> gvim --remote-silent <filename>

To reduce the amount of typing needed, we can put the same command in a batch script file. We can also add a condition that starts a new instance of gVim or reuses an existing instance.

REM gvimr.bat
@echo off
tasklist /fi "imagename eq gvim.exe" 2>NUL | findstr /i gvim\.exe 2>NUL
if "%ERRORLEVEL%" == "1" (
    call gvim.bat --servername GVIMR %*
) else (
    if NOT "%~1" == "" (call gvim.bat --servername GVIMR --remote-silent %*)
)

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.