Vim’s ability to execute commands from vim itself adds a great deal of productivity. Although, it’s debatable that it’s the best editor for Java, I made an attempt to work with maven3 inside vim and integrate it with vim’s quick fix list. Disclaimer: I’m not a vim expert, just an enthusiast. Please drop a comment as this tip is in need of improvements.
First, change make to work with maven. I’ve added -q so that only errors will reach the console.
set makeprg=mvn\ compile\ -q\ -f\ pom.xml
Change the error format to match maven3 output. Disclaimer: This is not perfect, but it manages to pick up the maven3 errors.
set errorformat=[ERROR]\ %f:[%l%.%c]%m
Change your working directory to the root of the maven project with :cd
Execute make with :make
Here’s the output I get.
Now, if you have errors it should show in the quick fix list as depicted below (Use :copen to open the quick fix list)
Now navigate and fix with :cn and :cp. Cheers!
One thought on “Using maven3 with vim”