Vimer初成长,Vim + ctags + cscope 这个组合基本是每个Vimer的必备吧。虽然ctags已经足够强大,但是cscope可以做的更多。下面来分享下自己的vimrc脚本关于cscope 的一部分,该脚本可以实现在项目的任一子目录下,自动的向上查找cscope.out,并把他add进来。
首先来分享一个小脚本,可以帮助我们在项目中生成cscope.out 和ctags。
我把这个文件命名为cs.sh
[java] view plain copy #!/bin/sh find . -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.java"\ >cscope.files cscope -bkq -i cscope.files ctags -R上边用find . 的方式,可能会造成cs找不到文件,可以find $PWD xxxx即可.
需要的注意的是,上面的脚本中,生成的cscope.files中保存的是相对路径,而不是绝对路径。这样的话,在cscope 中查找tags的时候,是没法打开相应的包含查找结果的文件的。怎么避免这个问题呢?有如下两个方法:
1, 在cs.sh的脚本中,find命令后接一个变量PRO_PATH,这个PRO_PATH是当前项目的跟目录,这个时候cscope.files中保存的就是所有项目文件的绝对路径了。
2,在:cs add的时候,接一个prepend path
[java] view plain copy :cs add [cscope.out] [pre-path]我用了第二个方法,所以就有了下面的vimrc片段,
[java] view plain copy if has("cscope") set csprg=/usr/bin/cscope set csto=0 set cst set csverb set cspc=3 "add any database in current dir if filereadable("cscope.out") cs add cscope.out "else search cscope.out elsewhere else let cscope_file=findfile("cscope.out", ".;") let cscope_pre=matchstr(cscope_file, ".*/") if !empty(cscope_file) && filereadable(cscope_file) exe "cs add" cscope_file cscope_pre endif endif endif转载于:https://www.cnblogs.com/linucos/archive/2013/03/23/2976836.html
相关资源:各显卡算力对照表!