I tried quite a few options available on the web to get an IDE like experience for Java programming in Vim. Eclipse was pretty heavy for me. On my windows machine it took about 300-400MB of RAM space, making system not so effective. Vim on the other hand had a few limitations that I thought could be worked out. Documenting my learning below for reference. (for me too🙂 )
Primarily I wanted to compile the code using maven. There is a maven vim script available, but that is a little dated. Also it did not conform to my needs. So I modified it a bit. Basically there are two entries that are of interest:
set makeprg=mvn\ compile\ -q\ -f\ .\pom.xml set errorformat=\[ERROR]\ %f:[%l\\,%v]\ %m
The first line here sets the program to be used to compile the program. Here I use maven to the current directory’s pom.xml to compile the code. Second line takes care of parsing the error output from the first line and allows the user to navigate through the code with the error list presented.
Also if you would like classical IDE mapping to compile and run, the following commands would help.
augroup vote if !exists("s:vote_init") let s:vote_init = 1 autocmd BufNewFile,BufRead */projects/java/roosamples/vote/* cd D:\projects\java\roosamples\vote autocmd BufNewFile,BufRead */projects/java/roosamples/vote/* compiler maven2 autocmd BufNewFile,BufRead */projects/java/roosamples/vote/* set tags=D:\projects\java\roosamples\vote\src\main\tags cscope add D:\projects\java\roosamples\vote\src\main\cscope.out map : !start cmd /c mvn tomcat:run map : make endif augroup END
Here I’ve mapped F5 to run and F6 to compile. Basically if I open any file in the directory of interest, the current directory, tags and compiler are set, with cscope added at the beginning of the file. One caveat here is autocmd uses / as the path separator even for windows. I still need to see how to enable debug support for java in vim. Another post I guess…