Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Ruby & HTML omnicomplete not showing local methods/variables

Hoping someone can help me out with some pretty erratic behaviour from omnicomplete in Vim with Ruby & HTML.

The problem is that Ctrl+X Ctrl+O only seems to return non-local commands. Method & variable names are left out. If I type Ctrl+X Ctrl+P they show as expected, but omni just isn't picking them up.

A few things:

  • --version confirms that Ruby in installed (+ruby)
  • I have rails.vim, snipmate and supertab installed - those are the only installed plugins I can think of that might possibly mess with ruby omnifunc
  • HTML omni has the same problem
  • Php & Python omni still works just fine
  • I've tried removing the HTML & Ruby-related sections below, but makes no difference - behaviour is the same

The .vimrc is below - any help much appreciated

" Set backup directory so that .swp files aren't stored in work folders
set backup
set backupdir=$HOME/temp/vim_backups/
set directory=$HOME/temp/vim_swp/

filetype on
filetype off

call pathogen#runtime_append_all_bundles()

syntax on
filetype plugin indent on

" Necessary for lot of cool vim things
set nocompatible

set tabstop=2
set smarttab
set shiftwidth=2
set autoindent
set expandtab
set wildmode=longest,list,full
set wildmenu

" Backspace should delete
set backspace=2 " make backspace work like most other apps

" For HTML
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

" For Ruby
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
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


" improve autocomplete menu color
highlight Pmenu ctermbg=230 gui=bold

" Remaps 'jj' to escape insert mode
inoremap jj <Esc>

" When closing tab, remove the buffer
set nohidden

" SuperTab Options
" let g:SuperTabDefaultCompletionType="<C-x><C-o>"
 let g:SuperTabDefaultCompletionType="context"
let g:SuperTabContextDefaultCompletionType="<C-X><C-O>"

" Close tags
imap ,/ </<C-X><C-O>
like image 913
PlankTon Avatar asked Dec 11 '10 06:12

PlankTon


1 Answers

Here are the relevant options:

set omnifunc=rubycomplete#Complete 
let g:rubycomplete_buffer_loading = 1 
let g:rubycomplete_classes_in_global = 1 

You're probably missing the complete_buffer_loading.

You can wrap this in autocmd's for the ruby filetype:

if has("autocmd")
    autocmd FileType ruby set omnifunc=rubycomplete#Complete
    autocmd FileType ruby let g:rubycomplete_buffer_loading=1
    autocmd FileType ruby let g:rubycomplete_classes_in_global=1
endif
like image 75
mkomitee Avatar answered Sep 22 '22 04:09

mkomitee