ctags with taglist in vim and python virtualenv
Asked Answered
F

1

6

I use virtualenv and django in my projects and I am trying to find a more efficient way to browse django source code.

As advised here - Tools to help developers reading class hierarchy faster - I got myself set-up with ctags via

sudo port -v install ctags

and installed the vim plugin taglist via https://github.com/vim-scripts/taglist.vim

Unfortunately, it seems that ctags cannot locate my django's class when I attempted to "jump" to view a class via Ctrl+].

Any suggestions how I can get ctags to read python source code located in my virtualenv?

UPDATES

With further experimentation, I realized that ctags is some kind of "indexing" program which parses through a given directory/files/file and grabs all the keywords (class names, method names, function names etc) it finds and writes it into a file. This file can be updated and vim plugin taglist essentially reads from it to know where to send me to when I do a Ctrlt on a class/method/function name.

So I came up with a temporary and manual solution, which I execute in my vim, like this:-

:set tags=~/mytags
:! ctags -R -o ~/mytags ~/.virtualenvs/myprojectname

The first command tells my vim/taglist where my "indexed" results are stored.

The second command writes the indexed results into ~/mytags file by searching recursively (-R) down the ~/.virtualenvs/myprojectname

This works but is a very manual way to maintain tags and tags change if I happen to be in a different virtualenv environment.

Does anyone know of an automated way to manage this ctags process?

Frogmouth answered 28/4, 2012 at 9:1 Comment(0)
T
5

There are many "automatic tags generation" plugins available.

TagList doesn't read from whatever tags you have manually/automatically generated: it's calling ctags itself and reads its output directly.

Also you might want to read :help autocommand. You could setup autocommands to re-generate your tags on write like this:

autocmd BufWritePost,FileWritePost *.py :silent! !ctags -R -o ~/mytags ~/.virtualenvs/myprojectname
Taxicab answered 28/4, 2012 at 11:6 Comment(2)
was your link pointing to some where? I am getting a 404. And regarding your example autocommand, it's a little more complicated that that because vim has to detect which python virtualenv I am in when it opens up a specific file and I am not sure there's a way to autodetect which virtualenv a project file "belongs" to.Frogmouth
Link fixed. Also see this plugin, it's supposed to make it easier to deal with virtualenv.Taxicab

© 2022 - 2024 — McMap. All rights reserved.