0

I am trying to make makeprg so that when I write :make it will compile my c program and if there are problems put them in Quickfix list and if there are non run the program and put output to Quick fix list

I am using

  • vim 9.0
  • zsh
  • g++ compiler on m1 mac
  • in alacrity emulator

this works but it doesn't execute the code:

set makeprg=g++\ -w\ -g\ %\ -o\ %:r

when I try this one:

CompilerSet makeprg=rm\ -fr\ %:r;g++\ -w\ -g\ %\ -o\ %:r&&./%:r

it goes like this:

(I have errors in my code) it shows me the errors then I hit enter I get blank screen with :

E40: Can't open error file /var/folders/hc/y4sccdy52y34th77l1lc0j_c0000gn/T/vTqwygm/3

(last three folders change every run)

then I hit another enter return to vim and contents of Quickfix list is unchanged.

when I remove the error:

output of ./%:r is shown with no problems.

I added :

rm\ -fr\ %:r

because I thought that if there will be no executable to run for ./%:r it will not show in Quick fix

without that it always shows output of

rm\ -fr\ %:r

any help is much appreciated

romainl
  • 186,200
  • 21
  • 280
  • 313

1 Answers1

0

Vim is redirecting the output from makeprg to a file, hence the error: there is no output from ./%:r.

When you want run multiple commands, the output will be taken from the last one. Instead you need to create a subshell to run both commands, so the output of both is combined together:

set makeprg=(g++\ -w\ -g\ %\ -o\ %:r\ &&\ ./%:r)
svlasov
  • 9,923
  • 2
  • 38
  • 39