Thursday 9 August 2007

Making the most of vim: ant and javac

With a bit of rather tricky configuration it is possible integrate vim, ant and javac (the standard Java compiler).

First, vim allows us to set an external program to be called for the :make command. This goes in ~/.vimrc

set makeprg=ant

Now, when you issue a :make command to vim, it will call ant to build the project. Now with a bit more configuration, we can get vim to parse the error messages from javac and step through them.

Back to ~/.vimrc to tell vim what javac's messages look like:

set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,\%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#

Make sure that horrendous code goes on one line. It came from a bit of head scratching and a lot of vim's documentation.

Now, after a :make you can step forward and back through the compiler messages using :cn and :cp.

That is all the IDE I need -- just enough help without getting in the way.

4 comments:

Anonymous said...

good tip. I learned elsewhere that you can
get ant to use the formats
that vim knows about by default using the -emacs option thusly
set makeprg=ant\ -emacs

Abdel said...

Thank you! I'm a vim addict.

灰机 said...

But i always can't match the file name. Because the outputted file name is just a name without the path when compile failed. So the vim can't match it. Is there any let ant to print full path instead a literally file name?

Mike Wilson said...

Regarding matching file names:

I can't help with this I'm afraid, I retired from software development in 2008. It may be something to do with using newer compiler.

Mike