4

Up until last week, I had been using RubyMine for my Rails development. I know it has a vim plugin but I have been working on migrating my development to vim and tmux. I don't want to keep using the mouse and VIM gives me a lot more flexibility. I have found plugins and workarounds for almost all the features I care about except the "interpreted auto complete" functionality in my first screenshot below. RubyMine interprets the whole rails application and offers sorted-by-relevance suggestions (as you can see, it's showing me instance variables and methods for the class in question and the modules it includes) THEN it shows (less relevant) methods available on the Object class. It also shows the method signature when there's one.

Also, in my second screenshot, you can see how RubyMine offers autocompletion for core Ruby classes.

Compare this to the bottommost screenshot. I do have completion but there's no way to find what I'm looking for. I'm using ctags , YouCompleteMe, vim-rails, vim-ruby and I also tried installing eclim to see if it makes a difference.

Is there a plugin I've missed that can enhance my auto completion? It doesn't look like RubyMine is doing something super crazy. pry can give me the same 'power' if it were running in the same 'context'.

First Screenshot (RubyMine interpreted auto complete):

enter image description here

Second Screenshot (RubyMine core Ruby classes auto complete):

enter image description here

Third Screenshot (vim omnifunc + ctags):

enter image description here

Abdo
  • 13,549
  • 10
  • 79
  • 98
  • Obligatory Vim is not an IDE comment. Also possible duplicate of [Better autocomplete in VIM](http://stackoverflow.com/q/15723209/438329) – Peter Rincker Nov 13 '14 at 17:18
  • Vim does have the capability to be an IDE. My current setup is very powerful (especially with CtrlP, vim-rails, vim-fugitive, etc) and I've only switched to Vim less than a week ago. The OP there was asking for autocompletion, which I do have (I mentioned many solutions in my question but I'm not fully satisfied). I'm looking for interpreted autocompletion if there's any out there =) – Abdo Nov 13 '14 at 17:27
  • Haha... I revisited his question and it looks like I am asking for the same thing but I'm still not satisfied with the proposed answers. His question was asked over a year ago and obviously the technologies in question have changed; how can we re-ask the same question without "duplicating the question"? – Abdo Nov 13 '14 at 18:46
  • Hm, as you don't seem to be reluctant to install plugins, you could try [vim-monster](https://github.com/osyo-manga/vim-monster) and see if it makes a difference. This is a completion plugin for ruby, which uses [rcodetools](https://rubygems.org/gems/rcodetools) for a better completion. – Yosh Nov 14 '14 at 10:31
  • I forked tpope's `vim-ruby` yesterday and modified it so I can see method signatures now :-).. I still need to allow it to insert the whole definition for me when I complete and make sure it integrates well with YouCompleteMe and I'll post to github =) Thanks for your answer though! – Abdo Nov 15 '14 at 09:58
  • how did you end up doing with that Abdo? It's something I would be interested in. – whossname Jan 13 '17 at 06:49
  • @whossname I wrote my answer below :-) – Abdo Jan 13 '17 at 06:50
  • haha yeh, I saw it right after commenting. Do you still use that setup? – whossname Jan 13 '17 at 06:51
  • @whossname I used it for a bit but then switched back to YouCompleteMe as it is faster than Supertab (this might have changed after Vim 8's release). So I would give it a shot again. Personally, I started using named parameters more (since order doesn't matter) but yup, I should give supertab another shot now that you reminded me :-) – Abdo Jan 13 '17 at 06:58

1 Answers1

4

Important Note This solution only works for Ruby 1.9+

I forked 'vim-ruby' at https://github.com/zxiest/vim-ruby and modified it as such:

  • Method signatures now appear in completion.
  • I disabled sorting by name for methods.

Plugins and Settings

vim-rails I'm using vim-rails https://github.com/tpope/vim-rails

supertab I'm using supertab https://github.com/ervandew/supertab instead of YouCompleteMe (mentioned in my question) although YouCompleteMe is super fast and automatic but there are currently some compatibility issues between my it and my vim-ruby fork.

vim-easytags I'm using vim-easytags https://github.com/xolox/vim-easytags

Add this to your ~/.vimrc

:set tags=./tags;
:let g:easytags_dynamic_files = 1

Make sure to touch ./tags in your project directory.

Issue :UpdateTags -R **/*.* from vim in order for easytags to generate your tags file.

Remap omnicomplete

In order for omnicomplete to pop up, by default, we have to hit <C-X><C-O>. I remapped this to <C-Space> by inserting the following in my ~/.vimrc:

inoremap <C-@> <C-x><C-o>

I now press tab when I want supertab to complete my code and Ctrl+Space when I want omnicomplete to trigger and show method signatures for me. There's definitely a better way to integrate this (i.e. getting supertab to call omnicomplete after a dot)

And here goes the screenshot! Notice that method sorting being off allowed my custom resize method to appear on top and the signatures now appear in the completion (as well as in the editor when enter is pressed!)

enter image description here

Abdo
  • 13,549
  • 10
  • 79
  • 98