Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add autocomplete to Vim for non-standard Python libraries?

For example, I have a Python script using the Google App Engine SDK:

from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

The module db has a submodule Key, so I try to use autocomplete on it:

db.KTab

But at the bottom of the Vim window, I get the following:

-- Omni completion (^O^N^P) Pattern not found

How do I include the path to non-standard Python libraries so that Vim autocompletion can find them? And also display their docstrings?

like image 490
Kit Avatar asked Nov 12 '11 00:11

Kit


People also ask

Does vim have autocomplete for Python?

To use it, simply press [ctrl] + n or [ctrl] + p key while in edit mode. For example: However, we can *teach* vim to autocomplete much other stuff by using so-called Dictionaries. We can have auto-completion for Python, Ruby, PHP, Bash, and any other programming languages code with this idea.

Can you get autocomplete in Vim?

Beginning version 7, Vim started to introduce its auto-complete feature. By default, it works by auto-completing words that already existed in the file being edited. If enabled, it can also auto-complete syntax for various programming languages. To make the list cycle backwards, hit Ctrl + p.

How do I get suggestions in Vim?

file. to enter the *edit* mode and type any JavaScript keyword in the text editor and press *Ctrl + x* followed by *Ctrl + o*. Vim editor will show the possible auto-complete suggestions. document.

How do you autocomplete in Python?

(In Python Shell window, you can use TAB key besides the key combination of 'CTRL' and 'space' to invoke the built-in auto-completion feature.) Alternatively, you can choose the "Show Completions" in the main Edit menu to achieve the same as well.


1 Answers

You need to add your library files to your tags file. For instance, if you have installed the Google App Engine via pip in a virtual environment located in env/:

virtualenv --no-site-package env/
source env/bin/activate
pip install google_appengine

... then you should execute:

ctags -R --python-kinds=-i -o tags env/

If you did not install google_appengine through pip, then you should locate the path to your python libraries (hint: it should be indicated by $PYTHONPATH. And according to this reference page: "on Unix, this is usually .:/usr/local/lib/python.") and replace env/ by the path you found.

Finally, your .vimrc file should parse your tags file. For instance, in my .vimrc, I have:

set tags+=/path/to/my/tags
like image 67
Régis B. Avatar answered Sep 21 '22 16:09

Régis B.