In Neovim, my code compiles and runs fine with this command:
:term clang++ main.cpp -o main && ./main , but not in Vim.

When I run it in Vim the code neither compiles nor executes. I get the following error:

clang-10: error: no such file or directory: '&&'

but when I do :term, and inside it run clang++ main.cpp -o main && ./main, it works.

  • Welcome to Vi and Vim! Can you edit to be more specific with what you’re typing before you get the error?
    – D. Ben Knoble
    Commented Oct 23, 2020 at 13:39
  • Thank you @D.BenKnoble!! Edited. Commented Oct 23, 2020 at 13:48
  • 1
    && is a shell construct, so you need to run a shell that runs your clang command. Commented Oct 25, 2020 at 17:35

3 Answers 3


I don’t believe (though I can’t find reference to prove it) that :terminal in vim wraps the passed command in a shell. So to use shell features you need, e.g.,

terminal sh -c "clang++ main.cpp -o main && ./main"

By itself, however, :terminal starts 'shell', which is usually $SHELL.

  • Not work. =/ main.cpp: -c: line 0: unexpected EOF while looking for matching `'' main.cpp: -c: line 1: syntax error: unexpected end of file Commented Oct 23, 2020 at 14:07
  • It works. Thank you!! Can you edit your answer? Commented Oct 23, 2020 at 15:03

I download the source code of vim from the vim repository on github:


compile and install with:

make && make install

and the previous command works:

:term clang++ main.cpp -o main && ./main
  • @D.BenKnoble Better? Commented Oct 23, 2020 at 16:12
  • Sure. I guess some recent version used the shell, and yours didn't? FWIW, mine doesn't (8.2.1800)
    – D. Ben Knoble
    Commented Oct 23, 2020 at 16:19
  • apparently this is it. I recompiled vim because the vim --version command showed -clipboard and I like to copy to the clipboard with yy. And consequently fixed the original problem. Commented Oct 23, 2020 at 17:18
  • I have +clipboard, but who knows
    – D. Ben Knoble
    Commented Oct 23, 2020 at 17:32

I suggest to add the code_runner plugin to the confugration of Vim and you can run code for c++ c and c# and python.

  • Welcome to Vi and Vim SE and thank you for writing an answer. The question seems to be about compiling code while your answer is about running code. Maybe you could edit and clarify how your answer addresses the question?
    – Friedrich
    Commented Jan 8 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.