问题
I use vim for coding. When I have to compile the current file, Currently I use :!g++ % && ./a.out
or :make
.
The errors/output displayed are gone when I press enter and get back to the file. I wish the errors and output are displayed in a vertical split by the side. It would be nice if output and error streams are in separate buffers. How can this be done?
Errors and Output buffer(s) should be updated when I compile again and it should not create new buffers.
How can do this? some vim pluggin/function? or a oneliner :P?
回答1:
oneliner:
:make | copen
See http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix-window
回答2:
If you want compile and run if compile succeeded. (i.e !g++ % && ./a.out
)
Create a shells script with the following line,
g++ $1 -o /tmp/a.out && /tmp/a.out
Now set the makeprg like this.
set makeprg=compileNrun.sh\ %
Cannot set the whole command directly as makeprg because of &&
.
If set in makeprg directly, the above command will be expanded to,
!g++ file.C -o /tmp/a.out && /tmp/a.out 2>&1 | tee /tmp/errorFile
Hence compilation errors wont be redirected to the error file if compilation failed ;P as &&
takes precedence over |
来源:https://stackoverflow.com/questions/6549414/how-to-run-make-in-vim-and-open-results-in-a-split-window