Tips for using Vim as a Java IDE? [closed]

I'm addicted to Vim, it's now my de facto way of editing text files.

Being that it's mainly a text editor and not an IDE, has anyone got tricks for me to make it easier when developing Java apps?

Some questions I have:

  • How do I invoke a maven task without leaving vi?
  • Can I get code completion?
  • How's the syntax highlighting?

Anything else (other than "Don't do it!") that I should know about?

Asked by: Aida476 | Posted: 21-01-2022

Answer 1

Some tips:

  • Make sure you use vim (vi improved). Linux and some versions of UNIX symlink vi to vim.
  • You can get code completion with eclim
  • Or you can get vi functionality within Eclipse with viPlugin
  • Syntax highlighting is great with vim
  • Vim has good support for writing little macros like running ant/maven builds

Have fun :-)

Answered by: Alberta121 | Posted: 22-02-2022

Answer 2

I've been a Vim user for years. I'm starting to find myself starting up Eclipse occasionally (using the vi plugin, which, I have to say, has a variety of issues). The main reason is that Java builds take quite a while...and they are just getting slower and slower with the addition of highly componentized build-frameworks like maven. So validating your changes tends to take quite a while, which for me seems to often lead to stacking up a bunch of compile issues I have to resolve later, and filtering through the commit messages takes a while.

When I get too big of a queue of compile issues, I fire up Eclipse. It lets me make cake-work of the changes. It's slow, brutal to use, and not nearly as nice of an editor as Vim is (I've been using Vim for nearly a decade, so it's second nature to me). I find for precision editing—needing to fix a specific bug, needing to refactor some specific bit of logic, or something else...I simply can't be as efficient at editing in Eclipse as I can in Vim.

Also a tip:

:set path=**
:chdir your/project/root

This makes ^wf on a classname a very nice feature for navigating a large project.

So anyway, the skinny is, when I need to add a lot of new code, Vim seems to slow me down simply due to the time spent chasing down compilation issues and similar stuff. When I need to find and edit specific sources, though, Eclipse feels like a sledge hammer. I'm still waiting for the magical IDE for Vim. There's been three major attempts I know of. There's a pure viml IDE-type plugin which adds a lot of features but seems impossible to use. There's eclim, which I've had a lot of trouble with. And there's a plugin for Eclipse which actually embeds Vim. The last one seems the most promising for real serious Java EE work, but it doesn't seem to work very well or really integrate all of Eclipse's features with the embedded Vim.

Things like add a missing import with a keystroke, hilight code with typing issues, etc, seems to be invaluable from your IDE when working on a large Java project.

Answered by: Samantha571 | Posted: 22-02-2022

Answer 3

  • How do I invoke a maven task without leaving vi?

    Maven is no different than any other shell command:


    You can :set makeprg=mvn if you already have a favourite key mapping for :make.

  • Can I get code completion?

    Yes, eclim is great, a bridge between vim's editing efficiency and Eclipse's Java language-specific awareness.

    <C-n> and <C-p> are not-so-great, but amazingly helpful.

  • How's the syntax highlighting?

    More than good enough for a regex-based highligher.

You may want to consider tools for other vim+java purposes, like code templates (snippetEmu—default snippets suck, but customizability shines), searching for usages and going to declarations (eclim, grep, ctags), generating getters and setters (java_getset, or eclim), automatic imports (eclim). You might also need a java shell for quick experiments (the BeanShell, a.k.a. bsh).

Answered by: Melanie559 | Posted: 22-02-2022

Answer 4

I have just uploaded this Vim plugin for the development of Java Maven projects.

And don't forget to set the highlighting if you haven't already:

enter image description here

Answered by: Vanessa770 | Posted: 22-02-2022

Answer 5

I found the following summary very useful: The description of :make was for ant not maven, but otherwise a nice summary.

Answered by: Julia745 | Posted: 22-02-2022

Answer 6

I know this is quite a few years later but here are some interesting plugins. I have not tried either of these yet so YMMV.

EDIT: Oh an BTW, i've tried eclim off and on, but the reason I like vim is its lightness. Executing eclipse even on headless mode is just too much mental lifting for me.

EDIT2: I've been using playframework lately and this will probably work with maven builds too:

  • For compiling, you can configure VIM's make to run maven or in my case, run a build script, tee that to a file.

    autocmd Filetype java setl makeprg=play_compile
    autocmd Filetype java setl efm=%A\ %#[error]\ %f:%l:\ %m,%-Z\ %#[error]\ %p^,%-C%.%#

"play_compile" is just a compile script. It uses SBT so Maven should work just fine here. Even direct javac will work. This way, you can use VIM"s quickfix buffer (:cnext, :clist: cprev, etc).

  • For jumping around the classes, I use ctrl-p. Its beautiful. Use it. Faster than eclipse in jumping around files.

  • For jumping around methods, I use tagsearch with exuberant c-tags. Jump into method declarations by using ctrl-]. Go back using Ctrl-o. Doesnt work as good as eclipse, but it works good enough.

  • I use supertab for code completion. Javacomplete is pretty slow, so I stick with omni-complete. Again, not as accurate as eclipse, but its fast and works good enough for me.

Answered by: John740 | Posted: 22-02-2022

Answer 7

Use vim. ^-^ (gVim, to be precise)

You'll have it all (with some plugins).

Btw, snippetsEmu is a nice tool for coding with useful snippets (like in TextMate). You can use (or modify) a pre-made package or make your own.

Answered by: Nicole934 | Posted: 22-02-2022

Similar questions

java - Need some tips as to what a part of code does

I have an assignment to do, and my teacher provided me with a part of code which could help doin said assignment. But I am unsure of one part of it; String utenRepetisjon(String tekst){ String resultat = ""; for (int i = 0; i &lt; tekst.length(); i++){ if (!tekst.charAt(i), resultat){ //Here I need help, if someone could be an angel and explain to me what this line does: !tekst.charAt(i), ...

java - Any tips on how to fix my code?

Here is the problem: When given an array arr, return an array which contains only odd integers in the original order from arr. A Few Examples: youMakeMeOdd({1,2,3}) → {1, 3} youMakeMeOdd({1,3,5}) → {1, 3, 5} youMakeMeOdd({2,4,6}) → {} And here is my code: public int [] youMakeMeOdd(int [] arr) { int x=0; for (int ...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)