Programming Java with Vim

Viewed 66574

I have tested many editors out there, but Vim makes me addictive. I really wish to use Vim in all of my programming. I just tried to start learning the Java programming language and I have a huge book that I'm trying to start to read for that purpose, but the sad thing about it is that I don't have either a Java compiler or a .class file reader (called a JVM I think, but maybe I am just a noob too and I already have them but don't know how they work).

I do not wish to use another editor than Vim, that is not my purpose. I know that Vim can call external commands to compile and that I might have to enter some stuff in my _vimrc to let him do so (I use Windows Vista, sad, I know) but I have no idea what to look for and I have searched for days. Any Vim-lovers experts around that could give me a hand out? I see that little Vim command called :javac and it pisses me off to know it's not working yet...

7 Answers

Can I suggest that you use a decent IDE, and a VIM plugin? I used to be a VIM diehard, and only recently switched to using Eclipse with a VIM editor plugin.

Why? The productivity gains of using a modern IDE are enormous. For example, once you're able to navigate through the code by structure type (e.g. method call to list of implementations etc.) then the ctags mechanism in VIM just isn't enough. Once you use more than a couple of libraries (or stuff you're not familiar with) then the code completion / method suggestion / doc navigation will save you a world of grief.

However I love the VIM method of keyboard navigation etc. Hence I use an IDE with an appropriate plugin.

Here's an answer I provided to a very similar question. That contains the link to the Eclipse VIM plugin. It's not free, but will pay for itself very quickly.

Except for the JDK as mentioned by other answers, you might also want to try eclim. It makes VI a full Java IDE.

As eed3si9n points out, you will need the JDK in order to start compiling your Java programs. But your question seems to be more about setting up your editor so that you can automatically compile Java programs from within it.

There are a couple of ways to approach this, of course. The easiest way is to work out a single command to build the project. In Java, most large projects are compiled with ant, and learning how to use that will serve you very well in the long term.

Once you've set up ant (http://ant.apache.org/manual/install.html to start), you can set vi to automatically call it via the ":make" command, by putting in your _vimrc file:

set makeprg=C:\path-to-ant\ant

So the steps should be:

(1) Get the JDK and learn how to use that.

(2) Get ant and learn how to use that. (*)

(3) Set your vimrc up so that it knows to invoke ant when you type :make.

As always, setting up a system to automate something (like your compiles) is easier when you're already proficient at doing it manually.

(*) Note: My vim doesn't have the javac command, so I'm not sure how to configure the vim options necessary to make sure you load it. If nothing else, it would be good to make sure that your javac was in your PATH at the time you load the editor.

Best wishes!

you are going to need to get the Java Development Kit (JDK) which has the compiler etc, without that the javac command is not going to work.

Using Vim to write complex Java applications is a nice dream, but it's gonna be a short one :) I know you must be used with VIM(which is fine) but why not using a modern IDE to write a Java application? Most of the current IDEs allows to change the keyboard mapping, so you could bring VIM to your IDE editor...

A few years ago we had a new employee which had a similar dream...after one month he left, I think he realized changing an application with 0.5mil LOC cannot be done in Vim.

Just my $0.02.

Related