Question

I am using vim with - neocomplete, jedi-vim, supertab and trying to do autocompletion while typing the following line:

from django.shortcuts import get_object_or_404

If I press tab after django. - I get a drop-down containing

        sys                  file [FI]
        VERSION                   [O]
        __doc__                   [O]
         __path__                  [O]
         __name__                  [O]
         __file__                  [O]
         __package__               [O]
         get_version(...,***)      [O]
         __builtins__()            [O]

Instead of a directory listing - containing sub-ackages of django package. Howeever if I copy django folder from /usr/local/lib/python2.7/dist-packages/django to my local dir. pressing tab after django. gives

   bin.          dir  [FI]
   conf.         dir  [FI]
   contrib.      dir  [FI]
   core.         dir  [FI]
   .
   .

This is probably because neocomplete picks it up from local path and displays the directory listing.

But in neither case can i do

from django.shortcuts import get_object_or_404

because get_object_or_404 is defined in django/shortcuts/__init__.py and jedi-vim does not seem to pick it up. So my questions are:

  1. How to do autocomplete of packages using vim if they are not in immediate directory - but are present in the PYTHONPATH?

  2. How to include methods like get_object_or_404 in autocompletion (For this I tried using ctags on the whole /usr/local/lib/python2.7/dist-packages/django dir but this does not check with the intention of displaying methods in a specific package - it displays all the fuzzy matching tagged methods which leads to a lot of noise while coding)?

My ~/.vimrc specific to supertab, neocomplete and jedi-vim is as follows:

Bundle 'Shougo/neocomplete.vim'
let g:neocomplcache_enable_at_startup = 1
let g:acp_enableAtStartup = 0
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
let g:neocomplcache_enable_fuzzy_completion=0

Bundle 'ervandew/supertab'
set omnifunc=syntaxcomplete#Complete
"au FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
set completeopt=menu
let g:SuperTabDefaultCompletionType="context"
" to do text select via j/k
inoremap <expr> j ((pumvisible())?("\<C-n>"):("j"))
inoremap <expr> k ((pumvisible())?("\<C-p>"):("k"))

Bundle 'davidhalter/jedi-vim'
let g:jedi#popup_select_first = 0
let g:jedi#auto_vim_configuration = 1
let g:jedi#use_tabs_not_buffers = 1
let g:jedi#completions_enabled=0
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_definitions_command = "<leader>d"
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#completions_command = "<C-Space>"
let g:jedi#rename_command = "<leader>r"
let g:jedi#show_call_signatures = "1"
au FileType python setlocal completeopt-=preview
Was it helpful?

Solution 2

It was a silly mistake on my part. I thought that the option:

let g:jedi#completions_enabled=0

means that it will not auto complete with the first option. But switching this flag off disables auto completion - which I misunderstood. Keeping the value 1 - solves it.

OTHER TIPS

You might like to try YouCompleteMe (YCM): https://github.com/Valloric/YouCompleteMe

YCM obsoletes the following Vim plugins because it has all of their features plus extra:

clang_complete
AutoComplPop
Supertab
neocomplcache

I have been using it with Django and other packages (including virtual envoirments). It saves a lot of configuration work, and just works out of the box.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top