Does anyone know how to set up auto completion to work nicely with python, django, and vim?
I\'ve been trying to use pysmell, but I can\'t seem to get it set up corr
I've had good luck with exuberant-ctags for this.
I use this macro in my vimrc:
execute 'map :!/usr/bin/exuberant-ctags -f '.&tags.' --recurse '.$_P4ROOT.' '
You'll want to modify that slightly, so that it includes your python /site-packages/django/ directory as well as your own code.
Then, hit F2 inside vim to update the tags, and use the regular vim tag bindings to navigate.
First off, thank you for asking this question, as it forced me to figure this out myself and it's great!
Here is the page I used as a reference: PySmell v0.6 released : orestis.gr
setup.py install
command.PYSMELLTAGS
file for django by going to your site-packages/django
directory and running: pysmell . -o ~/PYSMELLTAGS.django
pysmell .
to generate the project PYSMELLTAGS filePYTHONPATH
(export PYTHONPATH=${PYTHONPATH}:/path/to/pysmell/
)vim .
)pysmell.vim
(:source /path/to/pysmell/pysmell.vim
):set omnifunc=pysmell#Complete
)I realize this is not a sustainable solution, but you should be able to use this as a start to getting it setup to always work (e.g., add the export to your .bashrc, add the :source to your .vimrc, setup autocmd FileType python set omnifunc=pysmell#Complete
, etc.)
Let me know if this is enough to get you started. It worked for me!
Edit
I simply added this to my .vimrc and as long as the PYSMELLTAGS
& PYSMELLTAGS.django
files are in my project root, it works fine without any other work:
python << EOF
import os
import sys
import vim
sys.path.append("/usr/local/python/lib/python2.5/site-packages")
EOF
exe ":source ~/src/pysmell/pysmell.vim"
autocmd FileType python set omnifunc=pysmell#Complete
(source: dispatched.ch)
You can set up VIM with buffers, buffer display, auto complete, even Py Doc display.
Here you go
Today, you not need special extentions for django autocomplete in vim. Make sure that you have vim with python support. To check it, type in xterm:
vim --version|grep python
+python -python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs ... ...
To make work autocomplete, add this lines in your .vimrc:
autocmd FileType python set omnifunc=pythoncomplete#Complete
if has("python")
python import sys,os
python sys.path.append('/home/sergey/workspace/django')
python os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoProject.settings'
endif
where:
Finally, save it and restart vim. Now, after '.', you press default ctrl-x ctrl-o to get your autocomplete.
As I wrote in other places, I developed Jedi. I really think it is far better than all the existing solutions (even PyCharm).
https://github.com/davidhalter/jedi-vim
It is built upon pythoncomplete and much much more powerful!
It works for complex code:
And has additional features:
There is a list of all possible features:
__call__
, __iter__
, __next__
,
__get__
, __getitem__
, __init__
getattr()
/ __getattr__
/ __getattribute__
sys.path
modificationsisinstance
checks for if/while/assert