domingo, 6 de enero de 2013

The ultimate Python autocompletion for Vim

This is what you'll get.

 Ok, first we need a working copy of the python library jedi.
So we use pip(you use pip right?) and install it system wide.
If you have a virtualenv active, first
$ deactivate
Then install it
sudo pip install jedi

Then lets install the plugins we will need, this step will vary, i use pathogen so all i have to do is clone the plugins' repos to my bundle dir and i'm done. If this is your case:
cd ~/.vim/bundle
git clone https://github.com/davidhalter/jedi-vim.git
git clone https://github.com/Shougo/neosnippet.git
git clone https://github.com/Shougo/neocomplcache.git

Otherwise visit those urls and follow their installation instructions.

Ok, this is the really valuable step, a copy paste. This settings are the work of a try and error. So just paste them in your .vimrc file and be done with it.

" NEOCOMPLCACHE SETTINGS
let g:neocomplcache_enable_at_startup = 1
imap <expr><TAB> neosnippet#expandable() ? "\<Plug>(neosnippet_expand_or_jump)" : pumvisible() ? "\<C-n>" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable() ? "\<Plug>(neosnippet_expand_or_jump)" :
let g:neocomplcache_force_overwrite_completefunc = 1
if !exists('g:neocomplcache_omni_functions')
  let g:neocomplcache_omni_functions = {}
endif
if !exists('g:neocomplcache_force_omni_patterns')
  let g:neocomplcache_force_omni_patterns = {}
endif
let g:neocomplcache_force_overwrite_completefunc = 1
let g:neocomplcache_force_omni_patterns['python'] = '[^. \t]\.\w*'
set ofu=syntaxcomplete#Complete
au FileType python set omnifunc=pythoncomplete#Complete
au FileType python let b:did_ftplugin = 1
" Vim-jedi settings
let g:jedi#popup_on_dot = 0

And if you don't have filetype and indent detection in your vim
filetype plugin indent on

And that is it, if you have Vim open, close it and open it again. Enjoy your awesome autocompletion.