Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to set up good autocompletion for Ruby in Vim?

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.

like image 852
bluediapente Avatar asked Aug 31 '11 16:08

bluediapente


2 Answers

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| }.

like image 84
Kris Avatar answered Sep 22 '22 00:09

Kris


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.

like image 30
Xavier T. Avatar answered Sep 21 '22 00:09

Xavier T.