在vim和python virtualenv中具有标签列表的ctags [英] ctags with taglist in vim and python virtualenv

查看:141
本文介绍了在vim和python virtualenv中具有标签列表的ctags的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用virtualenvdjango,并且我试图找到一种更有效的方式来浏览Django源代码.

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

此处建议-帮助开发人员更快地阅读类层次结构的工具-我通过设置了ctags了

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

sudo port -v install ctags

并通过 https://github.com/vim-安装了vim插件taglist.脚本/taglist.vim

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

不幸的是,当我试图通过 Ctrl +] 来跳转"查看一个类时,似乎ctags找不到我的django的类.

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

关于如何获取ctags来阅读位于virtualenv中的python源代码的任何建议?

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

更新

通过进一步的实验,我意识到ctags是某种索引"程序,它通过给定的目录/文件/文件进行解析,并捕获其找到的所有关键字(类名,方法名,函数名等)并将其写入文件.该文件可以更新,并且vim插件taglist可以从中读取内容,以了解在对类/方法/函数名称进行 Ctrl t 时将我发送到哪里.

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.

所以我想出了一个临时的手动解决方案,可以在我的vim中执行,就像这样:-

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

第一个命令告诉我的vim/taglist我的索引"结果存储在哪里.

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

第二个命令通过在~/.virtualenvs/myprojectname上递归搜索(-R),将索引结果写入~/mytags文件中.

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

这可行,但是如果我碰巧在另一个virtualenv环境中,这是维护标签和标签更改的非常手动的方式.

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

有人知道自动方法来管理此ctags流程吗?

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

推荐答案

有很多自动标签生成"插件可用.

TagList不会从您手动/自动生成的任何tags中读取:它本身会调用ctags并直接读取其输出.

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

此外,您可能需要阅读:help autocommand.您可以设置自动命令来重新生成tags,如下所示:

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

这篇关于在vim和python virtualenv中具有标签列表的ctags的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆