I create some useful vim command aliases like:
command GccAndRun !gcc main.c && ./a.out
However, it's better to run a.out
and check source code in same window.
I here about vim internel terminal, so I write the follwing sentence:
command GccAndRun terminal gcc main.c && ./a.out
But given error message: gcc: error: &&: No such file or directory
in opened terminal.
I don't know how to fix it. Please help me!
Let's start by fixing your initial command, which can't work as-is:
command GccAndRun !gcc main.c && ./a.out
Now, :terminal
unfortunately doesn't accept constructs like cmd1 && cmd2
or cmd1 | cmd2
, so you will need a workaround:
create a shell script, say run.sh
, that does gcc main.c && ./a.out
for you and do:
command GccAndRun terminal run.sh
Pros:
Cons:
use the ++shell
option, which tells Vim to run the given command in a non-interactive shell:
command GccAndRun terminal ++shell gcc main.c && ./a.out
Pros:
Cons:
See :help :terminal
.