Autocomplete Vim, Python and Django (pysmell?)

Does anyone know how to configure auto-completion to work well with python, django and vim?

I am trying to use pysmell, but I cannot configure it correctly (or maybe I do not know how this works). Right now, I run pysmell in the django directory (I use the trunk) and move the received tags to my project directory, and then run pysmell in the project directory. However, Vim does not pick up django tags, and they do not get auto-complete.

Does anyone know how to configure auto-completion in vim so that it completes long django functions (e.g. get_object_or_404) as well as classes / functions in my own code? I poked on google but did not find any good resources.

Thank.

+47
python vim django
Jun 10 '09 at 23:35
source share
5 answers

First of all, thank you for asking this question, because it made me understand it myself, and it's great!

Here is the page I used as a link: PySmell v0.6 released: orestis.gr

  • Install PySmell using the setup.py install command.
  • Create the PYSMELLTAGS file for django by going to your site-packages/django directory and running: pysmell . -o ~/PYSMELLTAGS.django pysmell . -o ~/PYSMELLTAGS.django
  • Copy this file to the project directory, and then run pysmell . to generate the PYSMELLTAGS project file
  • Make sure pysmell is in your PYTHONPATH ( export PYTHONPATH=${PYTHONPATH}:/path/to/pysmell/ )
  • Run vim ( vim . )
  • Source pysmell.vim ( :source /path/to/pysmell/pysmell.vim )
  • Set the autocomplete command ( :set omnifunc=pysmell#Complete )
  • Enter ^ x ^ o for autocomplete and it should work

I understand that this is not a sustainable solution, but you should be able to use it as a start to configure it to always work (for example, add an export to your .bashrc, add: 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 just added this to my .vimrc and as long as the PYSMELLTAGS and PYSMELLTAGS.django are in my project root directory, 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 
+30
Jun 11 '09 at 0:32
source share
— -

alt text http://blog.dispatched.ch/wp-content/uploads/2009/05/vim-as-python-ide.png

You can configure VIM with buffers, display buffers, auto complete, even display Py Doc.

Here you go

+12
Jun 11 '09 at 4:43
source share

As I wrote elsewhere, I developed a Jedi. I really think this is much better than all existing solutions (even PyCharm).

https://github.com/davidhalter/jedi-vim

It is built on pythoncomplete and much more powerful!

It works for complex code: completion

And has additional functions: enter image description here

There is a list of all the possibilities:

  • built-in functions / classes support
  • complex structures of modules / functions / classes
  • ignores syntax and indentation errors
  • multiple returns / exits
  • tuple assignments / index indexing / dictionary indexing
  • exceptions / with-statement
  • * args / ** kwargs
  • decorators
  • descriptors -> property / staticmethod / classmethod
  • closing
  • generators (yield statement) / iterators
  • support for some magic methods: __call__ , __iter__ , __next__ , __get__ , __getitem__ , __init__
  • support list.append, set.add, list.extend, etc.
  • (nested) list / ternary expressions
  • relative imports
  • getattr() / __getattr__ / __getattribute__
  • functional annotations (py3k function, ignored right now, but parsed. I don't know what to do with them.) Class decorators
  • (the py3k function is also ignored until I find a use case that doesn't work with Jedi)
  • simple / regular sys.path modifications
  • isinstance checks if / while / assert
+12
Oct. 14 '12 at 19:00
source share

I was lucky with exuberant ctags for this.

I use this macro in my vimrc:

 execute 'map:! / usr / bin / exuberant-ctags -f'. & tags. '  --recurse '. $ _ P4ROOT.'  ''

You need to modify it a bit so that it includes the python / site-packages / django / directory, as well as your own code.

Then press F2 inside vim to update the tags, and use the usual vim tag bindings for navigation.

+3
Jun 11 '09 at 0:26
source share

Today you do not need special extensions for django autocomplete in vim. Make sure you have vim with python support. To check it, type xterm:

vim --version | grep python

Exit:

+ python -python3 + quickfix + reltime + rightleft -ruby + scrollbind + signs ......

To make autocomplete work, add these lines to 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:

  • sys.path.append is the path to the django workstation directory.
  • djangoProject is the name of your django project, which happens immediately after '/ home / sergey / workspace / django'

Finally, save it and restart vim. Now, after ".", You press ctrl-x ctrl-o by default to get your autocomplete.

+2
May 19, '12 at 15:01
source share



All Articles