ctags with taglist in vim and python virtualenv

我与影子孤独终老i 提交于 2019-12-06 02:15:11

问题


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?


回答1:


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 autocmmand. You could setup autocommands to re-generate your tags on write like this:

autocmd BufWritePost,FileWritePost *.py :silent! !ctags -R -o ~/mytags ~/.virtualenvs/myprojectname


来源:https://stackoverflow.com/questions/10362085/ctags-with-taglist-in-vim-and-python-virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!