Windows – Running vim script exits batch file? (Windows .BAT/.CMD)

batchbatch filecommand linevimwindows

Trying to run a vim script as part of a batch file with

vim -u NONE -S dothis.vim

but what is puzzling is that the batch file exits after this line instead of continuing with the next statement. This happens if the command is inline or is CALLed as a subroutine. If i create another batch file to CALL this command, my main batch will continue executing but on the screen nothing is displayed anymore except "Please press any key . . . " (actual words might differ slightly, dont have it visible on screen anymore), can't see the execution of the batch file anymore (would be important in this case).

dothis.vim is exited with qa! if this would have something to do with the issue (files have been update'd already); it autoedits a bunch of files in subfolders.

Best Answer

The "vim" which is running is probably a .bat file itself. That's what the default installer creates for you, anyway.

When you directly use one .bat file from another, the first .bat file no longer runs, it transfers control to the second without ever returning.

So this will end your .bat file:

vim -u NONE -S dothis.vim

But this should work:

call vim -u NONE -S dothis.vim

Now, you said "this happens if the command is inline or is CALLed as a subroutine". So, did you try this? Because this .bat file works just fine for me:

@echo off
setlocal

echo starting Vim
call vim -u NONE -S dothis.vim
echo Vim done!

endlocal
echo on

When I call this .bat file, I see both echo messages as expected.

I looked at C:\Windows\vim.bat and verified that there are no exit statements anywhere, which could cause problems in the first .bat file if done incorrectly. If this approach does not work, try posting a full .bat file that does not work for you. As I said, the above works for me just fine. Omitting call makes only the first echo statement run.

Related Question