0

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 Oct 23 '20 at 13:39
  • Thank you @D.BenKnoble!! Edited. – Lucas Martins Soares Oct 23 '20 at 13:48
  • && is a shell construct, so you need to run a shell that runs your clang command. – Christian Brabandt Oct 25 '20 at 17:35
1

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 – Lucas Martins Soares Oct 23 '20 at 14:07
  • It works. Thank you!! Can you edit your answer? – Lucas Martins Soares Oct 23 '20 at 15:03
0

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

https://github.com/vim/vim

compile and install with:

make && make install

and the previous command works:

:term clang++ main.cpp -o main && ./main
  • @D.BenKnoble Better? – Lucas Martins Soares Oct 23 '20 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 Oct 23 '20 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. – Lucas Martins Soares Oct 23 '20 at 17:18
  • I have +clipboard, but who knows – D. Ben Knoble Oct 23 '20 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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