2014-02-09 108 views
3

我一直在使用ctags与下面的vim脚本,并没有问题做我自己的小项目。但是当我进入一些大型项目时,在用C++编写的游戏中,ctags和cscope的递归命令似乎比我想象的慢得多。我实际上已经设法在背景上运行它,但似乎我的笔记本电脑非常忙于做标签。任何人都可以为我推荐更好的ctags解决方案吗?

我听说有一个解决方案,在每个子目录中制作一个标签,当您在特定的子目录中工作时,您可以查阅其他子目录的根目录中的标签,目录标签。这可能吗?如果任何人都可以用这种方法给我具体的HOW-TOS,我将非常感激。

或者如果有更好的解决方案,我非常想知道它。

这里是我的Vim脚本

function! UpdateTags() 
    let curdir = getcwd() 
    let gitdir = finddir('.git', '.;/') 

    if isdirectory(gitdir) 
     let l:rootdir = fnamemodify(gitdir, ':h') 
     execute 'silent cd ' . l:rootdir 
     execute 'silent !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q &' 
     if has("cscope") 
      execute 'silent !cscope -Rbkq &' 
      execute 'silent cs reset' 
     endif " has("cscope") 
     execute 'silent cd ' . curdir 
    endif 
endfunction 
+0

一个可能的解决方案:[简单的标签与Git](http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html) –

+0

你能告诉我们你的'标签的价值是什么'选项? – romainl

+0

您提到的多个标记文件的方法在ctags主页上进行了解释:http://ctags.sourceforge.net/faq.html#15 - 但我不确定您是否会找到根标记的更新文件更快。 – mMontu

回答

1

我发现使用ctags -R比使用的ctags与像ctags -L input我在我当前的Java项目,这样做有什么用大约3000文件是文件慢的代码要求git给我文件路径,将它们收集到一个存档(例如,javafiles.txt),然后在编辑器外部执行ctags -L javafiles.txt

如果你不想离开vim,你可以使用shellscript来调用带有你想要的参数的Ctags。 I.E.通过下面的代码创建你自己的Git项目的根文件autotags.sh

#!/bin/bash 

set -e 
git ls-files | sed "/\.cpp$/!d" >> cscope.files 


ctags -L cscope.files 

不要忘了给它执行权限。一旦你的shell脚本的vim脚本代码看起来就像这样:

function! UpdateTags() 
    let curdir = getcwd() 
    let gitdir = finddir('.git', '.;/') 

    if isdirectory(gitdir) 
     let l:rootdir = fnamemodify(gitdir, ':h') 
     execute 'silent cd ' . l:rootdir 
     execute 'silent !./autotags.sh &' 
     if has("cscope") 
      execute 'silent !cscope -bkq &' 
      execute 'silent cs reset' 
     endif " has("cscope") 
     execute 'silent cd ' . curdir 
    endif 
endfunction 

的文件名是cscope.files因为它的名字让cscope默认使用。你应该阅读http://cscope.sourceforge.net/large_projects.html

但是生成的文件列表是不一样快,你可能想和代码需要一些调整,以逃避这一步不是在需要的时候,但总的来说,这是比使用递归扫描与ctagscscope更快。

相关问题