Search code examples
javavimomnicomplete

vim java omnicomplete


I'm doing my best to follow the directions for install here: http://vim.sourceforge.net/scripts/script.php?script_id=1785, but I can't get it working and it seems sort of vague.

Here's what I've done.

  • I verified that I've got vim 7 or higher.
  • I created a $HOME/.vim directory
  • I unzipped the latest into $HOME/.vim
  • I added the following two lines to .vimrc:

:setlocal omnifunc=javacomplete#Complete
:setlocal completefunc=javacomplete#CompleteParamsInfo

From there I'm not sure what I'm supposed to do to get it working. Ideas?


Solution

  • The :setlocal command set only the value for the current buffer and it makes no difference inside .vimrc. Instead, you should tell vim to set the value for every file of type java. This is how it is done:

    if has("autocmd")
      autocmd Filetype java setlocal omnifunc=javacomplete#Complete
      autocmd Filetype java setlocal completefunc=javacomplete#CompleteParamsInfo
    endif
    

    Replace the commands in your .vimrc with the lines above and reload it (you can run :source ~/.vimrc for that).

    Notice that you need autocmd for that (you must observe the value 1 when running :echo has("autocmd") inside vim).