How to run make in vim and open results in a split window?

给你一囗甜甜゛ 提交于 2019-12-03 01:43:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!