I'm trying to write a function to open a split terminal in Vim and then run the current file in that terminal. A non-working example trying to explain what I'm trying to do is
function! Foo()
:bel term
%
endfunction
This just opens up the terminal. I tried with another command, dir
, and it seems it's fails because dir
is not a Vim command, so it's still trying to run things in Vim rather than the terminal. I also tried putting the command on the same line e.g. :bel term %
but I get an error:
Error detected while processing function Foo:
line 2:
CreateProcess failed
And the terminal doesn't even open.
I also tried
function! Foo()
:bel term
!dir
endfunction
though that had the expected result of essentially running !dir
and then returning me to a split window with nothing in the terminal there.
I've also tried to use the feedkeys()
function but I can't find a way to automatically pass the file name in.
I can't see anything relevant on :help terminal
. I've also found two relevant posts (post 1, post 2) but both seem to use Linux/bash and I'm on Windows, and those solutions aren't working.
How could I achieve this? If it's relevant I'm running Vim on Windows through cmd.