PlankTon
PlankTon

Reputation: 12605

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:

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>

Upvotes: 7

Views: 3993

Answers (2)

mkomitee
mkomitee

Reputation: 760

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

Upvotes: 14

the Tin Man
the Tin Man

Reputation: 160551

I use CTRL-X CTRL-N and CTRL-X CTRL-P when I need autocompletion. It's always worked in every filetype for every language and that's all I can ask.

Upvotes: 0

Related Questions