I'm trying to configure vim for python development. Right now I'm working on code autocompletion feature. I'm using YouCompleteMe plugin and it seems to be working great but only when I've already imported given module. For example, if I type

import datetime

and then


I get list of available classes/modules/functions etc. What I'm missing is the possibility to get module suggestions when writing import statements. Datetime module seem to be trivial in this case, so I use Django framework as an example. I'd like to achieve something like this:

from django.

lists all modules within django, I choose one of them, e.g. views

from django.views.

lists all modules within django.views, I choose e.g. generic

from django.views.generic import

And then I'd like to have autocompletion of classes, functions, variables available from this module e.g.

from django.views.generic import TemplateView

Do you have any suggestion how this can be achieved?


I realize this is very late but I found this question long before I came across the answer so I'm leaving this here. By adding the following to your .vimrc file you can load in your python virtualenv and then set a few ycm settings.

" python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))

let g:ycm_server_python_interpreter='python3'
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.