1

I'm trying to get omnicomplete working in neovim (0.3.4) on debian 10 with Ruby 2.6.6 (rbenv).

I have these plugins:

Plug 'vim-ruby/vim-ruby'                " ruby                                                                                                                        
Plug 'tpope/vim-rails'                  " rails 

With these settings:

autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1                                                                                                     
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1                                                                                                  
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1 

I get this error when trying omnicomplete:

option 'omnifunc' is not set

If I add this:

autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete 

I get this error:

Error: falling back to syntax completion
E117: Unknown function: rubycomplete#Complete

But after I click this error away it seems to work? What am I doing wrong? (I'm not interested in other plugins like deoplete, ...)

Update:
When I change

autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete 

to

autocmd FileType ruby,eruby set omnifunc=syntaxcomplete#Complete 

it seems to work. Not sure if that is the correct way?

update 2:

In Neovim you can check if Ruby is installed with :checkhealth.

In Debian 10 you can install ruby-neovim if you use the system Ruby version.

Since I use rbenv I did this:

gem install neovim

.vimrc settings:

let g:ruby_host_prog = '~/.rbenv/shims/neovim-ruby-host'
let g:ruby_path = system('echo $HOME/.rbenv/shims')
let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_classes_in_global = 1
let g:rubycomplete_rails = 1

There was also a bug in vim-ruby for the completion, but that is now fixed: https://github.com/vim-ruby/vim-ruby/pull/415

4
  • 1
    What if you take the global variables out of the autocommand? Theyre global, and it shouldn’t do any harm to just set them in your vimrc.
    – D. Ben Knoble
    Apr 4, 2020 at 14:12
  • good suggestion, but it doesn't make a difference
    – roeland
    Apr 4, 2020 at 14:56
  • The vim-ruby plugin should already set omnifunc to rubycomplete#Complete if the filetype is ruby and your Vim has support for Ruby. Can you check that :set ft? returns filetype=ruby? Can you check that :version includes +ruby in the list of features?
    – filbranden
    Apr 6, 2020 at 0:05
  • +1 to what @D.BenKnoble said. Set those globals in your vimrc directly, not as autocmd's.
    – filbranden
    Apr 6, 2020 at 0:06

1 Answer 1

1

From the error message you're getting, it seems your Vim doesn't have Ruby support compiled in.

See this code snippet:

if !has('ruby')
    call s:ErrMsg( "Error: Rubycomplete requires vim compiled with +ruby" )
    call s:ErrMsg( "Error: falling back to syntax completion" )
    " lets fall back to syntax completion
    setlocal omnifunc=syntaxcomplete#Complete
    finish
endif

The error message in bold is the one you're seeing. (If you type :messages you'll probably see the other, more explicit error message, about support for Ruby missing.)

You can confirm that Ruby support is missing by using the :version command in Vim to get a list of features. You'll see -ruby, since you're missing Ruby support. (You'd see +ruby if it was available.)

From your question, you're using NeoVim on Debian Buster, so maybe try installing the ruby-neovim package to see if that solves the problem and enables Ruby support on your NeoVim?


set omnifunc=syntaxcomplete#Complete seems to work. Not sure if that is the correct way?

That is going to give you some completion, but probably not as rich as the Ruby-specific completion from rubycomplete.

The syntaxcomplete#Complete function will use Vim's syntax highlighting rules to offer insert completion, which for the most part covers language keywords that are highlighted by syntax rules.

See :help ft-syntax-omni:

Vim has the ability to color syntax highlight nearly 500 languages. Part of this highlighting includes knowing what keywords are part of a language. Many filetypes already have custom completion scripts written for them, the syntaxcomplete plugin provides basic completion for all other filetypes. It does this by populating the omni completion list with the text Vim already knows how to color highlight. It can be used for any filetype and provides a minimal language-sensitive completion.

So this might be adequate and better than nothing... But I'd expect you'd get superior completion by using rubycomplete instead.


With these settings:

autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1

These are globals and are intended to be set directly from your vimrc and not in a filetype autocmd.

This might be important since you might have ordering issues (these are only set after the vim-ruby plugins try to inspect them, producing the incorrect result), or you might get different behavior from the first Ruby file you edit to the subsequent ones (since the first one sets them globally, they'll already be set when the second file is opened.)

Just avoid these issues altogether by setting them directly, as intended:

let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_classes_in_global = 1
let g:rubycomplete_rails = 1
3
  • 1
    yes, I didn't had ruby-neovim installed. Now the error is gone, but I get the message 'pattern not found'. (also in vim-nox). Syntaxcomplete seems to give better results? (In a model I try to complete 'val')
    – roeland
    Apr 6, 2020 at 7:34
  • 1
    could be a problem with system ruby vs rbenv ruby. I'll have to investigate, but the problem I asked is solved.
    – roeland
    Apr 6, 2020 at 7:40
  • See :help ft-ruby-omni for more on what to expect from Ruby ommi completion. Note it uses 'require' option to find other files in your project (but it seems you can't even complete from the same file.) Also, I'd expect vim-ruby and vim-rails to take care of that setting for you... Unfortunately I don't know much more about rails or ruby... Yeah it could be related to rbenv ruby! Good luck, I hope you'll figure it out!
    – filbranden
    Apr 6, 2020 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.