Wikia

Vim Tips Wiki

Run make from command line and open Vim on errors

Talk0
1,612pages on
this wiki
Revision as of 05:19, July 13, 2012 by JohnBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Tip 219 Printable Monobook Previous Next

created 2002 · complexity basic · author scott urban · version 5.7


A simple alias (*csh) or shell function (bash) will let you run make from your shell, then automatically open vim or gvim on the errors (if there were any):

csh or tcsh:

alias Make 'make \!* |& tee make.errors || gvim -q make.errors -c :copen'

bash:

Make () { command make "$@" |& tee make.errors || gvim -q make.errors -c :copen ; }

If you use vanilla sh or ksh or even cmd.exe, you can probably do the same - add a note if you have ideas.

CommentsEdit

The '|&' before the 'tee' doesn't work on Bash version 3.00.15(1)-release. I had to take out '&' for it to run.

What does the '&' make the pipe do? Answer: pipes both stdout and stderr.


Is this somehow better than running make from within Vim using the :make command?

I have an alias like this:

alias vmake 'vim -c make! -c cwindow'

Much more elegant, in my opinion.


After added this to ~/.bashrc

Make () {
   make "$@" 3>&1 1>&2 2>&3 | tee make.errors
   N=`wc -l make.errors|cut -d ' ' -f 1`
   if [ $N"x" != "0x" ]; then
       vim -q make.errors -c :copen
   fi
}

Compiling your program, Ex:

#Make clean all

If error happened, then vim invokes automatically.

Around Wikia's network

Random Wiki