11

I've read heaps of blogs on Vim's supposedly great omnicompletion, and yet no matter what I do I can't get it to work satisfactorily. It took me ages to figure discover that the version of ctags that is preinstalled on my system was the emacs one, and didn't have the --recurse option, but now that I've run ctags-exuberant on my copy of the OpenJDK sources to attempt to get some kind of code completion going, Vim hangs whenever I try to invoke it with [C-n] or [C-p].

All I really want is something that works like the code completion in Eclipse; I like Vim as an editor, but Eclipse just has those extra features out-of-the-box which Vim seems to fail with. Eclipse with a vi-mode plugin wasn't particularly useful to me, and it is too much of a memory and CPU hog to be of any use; eclim doesn't quite like me either.

Can anyone suggest a simpler way to get some kind of code completion working in Vim that actually works?

Sean McMillan
  • 10,058
  • 6
  • 55
  • 65
Robbie
  • 111
  • 1
  • 1
  • 3

4 Answers4

8

Here is a "JDE" feature for vim: http://www.vim.org/scripts/script.php?script_id=1213 One of the listed features is "Code completion ( working for java and jsp,taglib,html,xml,xsl,xsd) (VIM 7.0 required) "

And here is a Java autocompletion script: http://vim.sourceforge.net/scripts/script.php?script_id=1785

This one isn't Java, but I found it to be quite clear and understandable; perhaps it might be worth reading. Here is a recipe on setting up autocompletion for Drupal. A custom AWK script builds an autocompletion dictionary for vim. http://www.thingy-ma-jig.co.uk/blog/18-08-2009/drupal-autocomplete-vim

Good luck.

steveha
  • 74,789
  • 21
  • 92
  • 117
  • 1
    Thanks for your suggestions. Have you tried JDE and javacomplete yourself? What's your preference? I've tried javacomplete but it does not always work for me (haven't dug into why). I'm off to have a look at JDE! – Hannes Jun 15 '11 at 08:15
5

I had a go with eclim:

http://eclim.sourceforge.net/

A while ago, it basically runs eclipse in the background and then provides a vim plugin which lets you get at all the functionality of eclipse inside vim. So you can do refactoring, completion etc. It seems to work quite well if you don't mind running a huge eclipse process in the background on your system.

I've got completion working quite well in C++ (Better than Vis stud anyway) but never had much luck with java. These days I tend to use eclipse most of the time but I have gvim --remote set up as an external command in eclipse so that I can just wip the current buffer into vim anytime I want.

Benj
  • 31,668
  • 17
  • 78
  • 127
  • 1
    By the way, that last para referred to vim's built in omni completion, not eclim. – Benj Oct 29 '09 at 11:24
1

I have looked for this as well as I am considering moving from eclipse to vim. The best solution I have found so far is to bring vim to eclipse with the vrapper( http://vrapper.sourceforge.net/ ). It brings a lot of the features of vim to the eclipse editor and you can still use autocompletion and all the other features of Eclipse.

I am still interested in moving completely, but it seems difficult to beat eclipse for a java development environment. (just hate the overhead for eclipse!)

Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141
  • Hint: vrapper it has the [C-p] completion. You just need to disable the print command (double CTRL+SHIFT+L, search for CTRL+P). Who ever needs to print code anyway? – Dacav Dec 09 '14 at 09:39
  • In general I noticed that you can get a very vim-like behavior by getting rid of default key-bindings, which have the priority over the ones defined by vrapper. – Dacav Dec 09 '14 at 11:08
1

Had the same desire, got it fulfilled by using eclim. Works really really well.