vim 7 ruby omni completion


I've hacked irb/completion into something resembling an omni-completion function for vim 7. It currently works for me. I looked at pycomplete.vim and ccomplete.vim to create it. There is a bit of work ahead as far as variable-type detection and require's are concerned. If you're feeling your oats and want to hack away at it, you'll find it here (rubycomplete.vim (0.7)). If you want to see the old versions check the release history. It was originally called rbcomplete.vim, but a discussion on the vim-dev mailing list led to a rename matching the filetype definitions. There are probably many improvements possible, I'll see how much I can make it do in the next few weeks. I've joined up with the vim-ruby project, so you can find the file in their cvs repository.

features: n.b.: rubycomplete evaluates code in vim, this could have side effects. As of version 0.6 rubycomplete no longer defaults to evaluating live buffers. This functionality can be toggled back on (I suggest you do so, as it increases the usefullness of the script). As a note loading rails takes a little bit so you will need to be patient when initially completing rails classes.

usage: add something similar to the following to your vimrc and place rbcomplete in your autoload directory

autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
if you want buffer/rails/global completion you must add the following:
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
if you want rails support add the following in addition
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
if you want classes included in global completions add the following
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1

open a ruby file, add some object call, say Array. and hit CTRL-X CTRL-O.

Obligatory screenshot
rbcomplete.vim screenshot