sheamus
sheamus

Reputation: 3153

What is best way to make Vim's omnicomplete context aware for ruby/rails? (i.e., intellisense)

Vim's auto complete seems like it is just throwing the the kitchen sink at me hoping that one of the words is something I need. If I know the first couple characters of the member method, I am ok, but sometimes I can't remember if the member method is 'obj.visible' or 'obj.is_visible', in which case I get 50-1000 options to wade through.

consider the following code:

  class MyClass
    def some_method
    end

    def another_method
    end
  end

  def a_global_method(stuff)
    return stuff + " more stuff"
  end

Now if I type

obj = MyClass.<c-x><c-o>

I get 50 some options, starting with '<'. 'new' would be a great default here. Heck even if I type the n, then cx/co new isn't the first option.

It gets worse:

obj = MyClass.new
obj.<c-x><c-o>

This gives me 50 options again, and maybe they are all legit, but why not default to 'some_method' and 'another_method'?

But wait, all options aren't legit:

obj = MyClass.new
obj.a<c-x><c-o>

This only gives me 2 options, but one of them is 'a_global_method'. So obviously it is completely unaware of what a class or module are, at least with my current settings. I might as well just use if I have to type half the member name anyway.

Speaking of which, a summary of my current settings is as follows: rails.vim with the following settings:

"omnifunc=rubycomplete#Complete is set by rails.vim
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
autocmd FileType ruby,eruby let g:rubycomplete_include_object = 1
autocmd FileType ruby,eruby let g:rubycomplete_include_objectspace = 1

I have been a loyal vim user for 12+ years, but the completion has never really worked correctly for me. I use Visual Studio at work, and use intellisense as a crutch quite often. As I don't code in rails often enough to have memorized every method, a little intellisense love would go a long way.

Is there any sort of plugin that works well? Am I just missing a setting?

Upvotes: 4

Views: 1460

Answers (1)

Ask and Learn
Ask and Learn

Reputation: 8959

Have you tried YouCompleteMe ?

Here YouCompleteme

Upvotes: 1

Related Questions