3

I'd like to be able to conveniently navigate to the file where a Python value (function/class/constant) is defined. Most of the guides I can find for using ctags with Python suggest options that aren't supported by the various ctags-like programs that I've found.

I've tried using vanilla ctags (/usr/bin/ctags on OS X), exuberant ctags (through brew), and etags (on OS X) to generate tags files for a Python project and have been somewhat dissatisfied with the out of the box results.

If I navigate to the project root and run ctags -R . I get a lot of lines like the following:

version_info    api-docs/venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/chardet/__init__.py /^from sys import version_info$/;"  i

A line like

from sys import version_info

appears literally in the Python source code.

The symbol version_info is defined in the sys module, which should be somewhere in the standard library in my virtualenv. When you do an unqualified import in Python, you really are copying the contents of the symbol to a new symbol in the current module, but most of the time I just want to jump to the place where the symbol was originally defined.

I get that the actual place where a symbol is defined depends on information only available at runtime like the PYTHONPATH, but a heuristic guess is better than nothing (there might also be a nice interface for cycling between symbols that are defined in multiple files built in to vim, I'm not sure).

closed as off-topic by mMontu, statox, muru Oct 12 '16 at 16:29

  • This question does not appear to be about Vi and Vim family of editors, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I'm voting to close this question as off-topic because it's not a question about Vim, but about ctags. – mMontu Oct 11 '16 at 19:19
  • 1
    A quick internet search on "ctags python" brought python-ctags 1.0.6, which you may find useful. The search also shows this guide, which explains how to disable import tags (such as the version_info you mentioned that are bothering you). – mMontu Oct 11 '16 at 19:23