When I compile and execute a c++ program in vim it outputs "command terminated" however when I compile it in geany (another ide) it outputs "segmentation fault". Is there a way to get vim to output the same message as geany?

  • That depends on how you compile and run it? What do you use? :make?
    – muru
    Aug 1 '15 at 0:58
  • @muru No, I just typed :!g++ E9.26.cpp then ran the program with :!./a.out.
    – The Enigma
    Aug 1 '15 at 1:32

When you do :!./a.out, the Segmentation fault message is printed by the shell that ran the command, not the command itself. You could run something like1:

:!{ ./a.out; } 2>&1

This redirects the stderr of the shell within the command group, so the message from the shell is also captured:

/bin/bash: line 1:  7153 Segmentation fault      (core dumped) ./a.out

shell returned 139

Press ENTER or type command to continue

Or run the command in a subshell:

:!( ./a.out; )

This has similar output to the above option.

With more complex programs, you'll probably end up using some sort of build system, such as make. In which case, the program won't be run directly by the shell, but by the makefile, so you'll get the error message.

1This depends on the shell. I'm assuming bash, and couldn't get the same effect from zsh.

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.