I do a lot of Java work at my day job and I use Vim as my primary
editor. However, I do it in conjunction with Eclipse. I thought I'd
share my experience here as it may be useful to you or others.

There are a couple of plugins for Eclipse that emulate vi-style editing
in Eclipse's built-in editor, but I was never really satisfied with
those. They force you to use whatever subset of Vim's commands the
plugin author decided to implement, and I was constantly running into
situations where I wanted to do something the "Vim way", but the plugin
wasn't sophisticated enough to support it.

There's also one plugin that embeds GVim within your Eclipse window, but
the integration seemed really flaky, and Eclipse seemed to crash or hang
even more often that it already does while I was running it.

Then there's Eclim <http://eclim.org/>, which allows you to run Eclipse
as a server and embed a lot of Eclipse's functionality inside of a Vim
session. Personally, though, I really don't like Eclipse, and I didn't
want to get any Eclipse in my Vim. Eclipse is an unfortunate necessity
for a lot of Java development, but I wanted to keep its usage to a
minimum.

What I eventually settled on was actually rather simple: First, I
created a small shell script as follows (this is Unix-specific, of
course, so it won't work if you're on Windows):

        #!/bin/bash

        if [[ $# -eq 0 ]]; then
                vim --servername ECLIPSE_SERVER "+set dir=~/tmp"
                exit
        fi

        if [[ -n "$(vim --serverlist | grep ECLIPSE_SERVER)" ]]; then
                vim --servername ECLIPSE_SERVER --remote "$1"
        else
                echo 'Vim server "ECLIPSE_SERVER" not running' >&2
                exit 1
        fi

This script is saved on my path as "vim_eclipse_launch". I can type that
filename on the command line to start a Vim session in server mode.
Then, in my Eclipse preferences, I add vim_eclipse_launch as an external
editor and associate various filetypes (*.java, *.jsp, *.xml,
*.properties, etc.) with that editor. That way, when I open a file from
within Eclipse, e.g. by clicking on the filename in the project
explorer, it pops up in my Vim window instead of in Eclipse's built-in
editor.

It helps to use this in conjunction with a tiling window manager like
xmonad or dwm, so you can have Vim and Eclipse easily positioned
side-by-side. I also use some popular Vim plugins like Taglist and
NERDTree to make it easier to manage large amounts of Java code within
Vim instead of having to jump back over to Eclipse for that sort of
thing. Over time, I've grown quite accustomed to working this way and I
think it's pretty much the best of both worlds. The only thing better
would be to eliminate Eclipse entirely, but that's really not feasible
with Java.

Anyway, this may not appeal to everyone, as you are still lacking
Eclipse's "intelligent" auto-completion when working this way, and there
are some other rough edges, such as the fact that Eclipse doesn't see
the edits you've made in the Vim session until you explicitly tell it to
refresh the file or project. But it works well enough for me, and it
makes me not hate working in Java so much anymore. A little Vim makes
anything better!

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to