Using Eclim (Vim + Eclipse) as an IDE for Java - Programming On Unix

Users browsing this thread: 1 Guest(s)
Ippytraxx
Members
After seeing z3bra's post about using Vim with Java, I was inspired to make my own tutorial on how to take it one step further.

Dependencies
* JDK
* Eclipse
* Eclimd (Easy installation through the AUR for Arch users)
* Vim

First time
Eclim has extremely good documentation so definitely go check it out if you are interested.

So first start eclimd or add it to your .xinitrc for autostart. This will launch a headless Eclipse instance that the Eclim Vim plugin can talk to.

After starting Vim, type :PingEclim to see if a connection has been made. If successful you should get a response like this:
[Image: Z0d0]

Project management
Eclim is not only for Java. It pretty much supports all the languages the Eclipse supports.

To create a new project type :ProjectCreate /path/to/project -n java. The java can be replaced with c, c++, ruby, php, etc. (This guide focuses on Java).

To see your current projects type :ProjectList and Eclim will open a new buffer showing you your open projects.

Eclim has many great IDE features ported to Vim. Here are some of my favourites:

* :ProjectTree Brings up a IDE style tree of your current project (pretty sure it's just a clone of NERDTree)
[Image: qAW]
* :ProjectTodo Shows you a list of TODO,FIXME, etc tags that you can easily go to. (use let g:EclimTodoSearchPattern = 'REGEX' in your .vimrc to define custom tags.
[Image: cb4H]
* :JavaRename HOLY CRAP, IDE refactoring in vim!!
* :JavaCorrect Let Eclipse suggest a correction
* :JavaFormat Format code according to preferences in Eclipse (shutdown eclimd, start GUI Eclipse, edit format style to your liking)
* :JavaImport Import detected libraries
* Ctrl-X + Ctrl-U (can be changed) brings up the autocomplete and another buffere that is more detailed (not shown)
[Image: 5K5]

Building
Eclim offers some basic functionality when it comes to building. With every newly created project, a .classpath file is created in the project's root. This file is the same one that eclipse uses. By default everything in the src/ directory is compiled and the main method is automatically detected in most cases. When editing the .classpath file, you can use extra commands like :NewSrcEntry JARFILE.jar, which will add a new source entry to your classpath.

To run you simply type :Java and it will attempt to build and run your project. The functionality is great for small to medium sized projects. However it can't handle everything, that's why you should use one of the wonderful Java build tools:

* ANT: Everyone knows this one. Rock-solid, good support although XML can be a bit challenging.
* Maven: Similar to ANT in the fact that it also uses XML, but it's much newer and easier to use. Pretty much the de-facto build tool for most people especially because it has a central repository for libraries, so adding them to your classpath is super easy.
* Gradle: New kid on the block that is picking up a lot of speed. Doesn't use XML and instead opts for Groovy like syntax. Also very easy to use, although I have run into some bugs here and there.

Summary
Well there you have it! A very brief overview and setup tutorial on how to really turbocharge your Java development in Vim. This setup has helped me immensely recently when my PSU on my main computer went kaputt and I was forced to use my crappy laptop. Eclim saved my life because I can use the lightweight Vim and not miss out on those IDE features that I love.

If you decide to try out Eclim, definitely check out the official documentation on their website (linked at top) as it goes through so much more and in depth.
Ippytraxx
Members
They have some android stuff. Android users. I'm guessing you won't get stuff like the Virtual Device Manager though.
srp
Long time nixers
Thank you for this great post, Ippytraxx. I'll definitely be setting this up next time I get on the slacktop!
~Seraphim R.P.
the artistnixer formerly known as vypr formerly known as sticky