9

I've been trying to set up Vim autocompletion for Ruby code and have not been successful. I mean things "work", but I would expect a better plugin or configuration to be available.

I've set up the rubycomplete plugin and it is doing a decent job, but nothing compared to an IDE like RubyMine. It was just a breath of fresh air once I installed it see what I was missing. It is well aware of syntax, context and usually shows only relevant possible options.

Maybe I just haven't set things up correctly. It's been impossible to find a tutorial, blog post, good documentation on how to go about this (especially one that is up to date). Sometimes you just find that there are different tools and setups and not much explanation on how to go about it.

Is there a community standard for this type of thing? What are the best tools to achieve this? Any good tutorial, source, clues on how to go about it?

I keep hearing people say that they prefer Vim over an IDE like Rubymine and that they can achieve pretty much the same behavior on many aspects with the proper plugin configuration, but my experience has not been the same. I really want to keep using Vim since it is lighter and I love the editor, but productivity is the most important thing and I'm wasting too much time reading blog posts from 3 and 4 years ago about how to set this up.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
bluediapente
  • 3,946
  • 5
  • 32
  • 38
  • There are very few IDEs with Ruby auto-complete.. mainly because Ruby is so dynamic that it's difficult to do. The only IDE I've seen with Ruby auto-complete support has been KomodoEdit, and it usually wasn't useful – Earlz Aug 31 '11 at 16:53
  • I don't see a list of requirements in your question. What do you want vim's omni-complete to do that it doesn't? I'm not into Ruby at all so I don't think I can really help but can you make your question more precise? – romainl Aug 31 '11 at 18:19
  • Similar question here : http://stackoverflow.com/q/4824507/513198 – Xavier T. Sep 01 '11 at 09:10
  • @romainl I wouldn't know about a list of features. It's more about having the suggestions be relevant instead of a random unordered list of things like it appears in Vim sometimes and it being aware of language, syntax, class relationships, etc. You'll know it if you test them side by side with the same code. I guess maybe it was too much to ask since Vim is not an IDE, but I read about people saying they were similar (maybe it was in the past) but for me something like RubyMine is way better and speeds up development so that I can focus on writing code instead of my tools getting in the way. – bluediapente Sep 01 '11 at 14:10
  • Vim is not an IDE, that's for sure. Omni-completion is not as powerful as most IDEs autocompletion because it lacks all the background compiling and all the advanced stuff they use to perform smart suggestion. I do JS/PHP mainly and for the most part vim's suggestions are relevant: with `var d = new Date();` using completion after "get" in `var y = d.get` shows the whole list of methods of the `Date` object. The same for a constructor, even with prototype-based methods. It's more than enough for me. Did you try [AutoComplPop](http://goo.gl/ooVX)? It makes suggestion automatic. – romainl Sep 01 '11 at 14:48
  • Also I was asking for an example of what is wrong and how you think things should work. – romainl Sep 01 '11 at 14:51

2 Answers2

2

You can, in insert mode, hit Ctrl + x, then Ctrl + o (omni) to get a list of Ruby methods. If you have already typed a few characters e.g ea you will get each, each_with_index etc.

In my vimfiles have Tab mapped to complete using another word in the buffer.

Its not as great as an IDE e.g Netbeans or Rubymine, but it works well enough.

After pressing Ctrl + x there are other combinations you can use complete using words, lines etc.

There is also eclimd which uses a headless Eclipse to provide auto complete but I've never managed to work out how to get it to work. Install and connecting Vim to Eclipse is easy enough, but after that...

Snipmate might be an alternative, ea<tab> with expand to each { |element| }.

Kris
  • 19,188
  • 9
  • 91
  • 111
1

For most operations where a fine understanding of the language is required, I generally find that Vim is lacking compared to a dedicated IDE.

For example, you can't automatically refactor code using scope (changing foo() into bar() in class Monkey but not in class Ape in your whole project).

Similarly, autocompletion is not always smart. I think that for C/C++ the situation is tolerable thanks to tools like clang_complete. But for Java, or less popular language, I got the feeling that completion script are not up to the task. So you end up spending a lots of your time tinkering with scripts. The problem is that for good autocompletion you need to leverage the full power of an interpreter or compiler, and apparently it is not easy to do.

Still I keep using Vim primarily because I am more efficient to edit chunk of code but when the situation requires it, I also use an IDE next to Vim.

I don't know the specific situation of Ruby complete, but I am not sure you'll get a positive answer.

My dream would be that every IDE had a mandatory full vi input mode.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
  • 2
    This is why I prefer vim emulation, for instance ViEmu in Visual Studio. You get the best of both worlds. – Earlz Aug 31 '11 at 16:52
  • @Earlz : I am using Viper in eclipse, it is nice but it is far too be a complete implementation. – Xavier T. Aug 31 '11 at 16:56