VI改造计划补充篇

在《VI改造计划》一文中讲述到了ctags和cscope两个工具,在使用Linux Kernel源码进行实操时需要使用:cs add cscope.out去加载cscope数据库,每次这样操作会让我们抓狂,那我们修改下~/.vimrc吧,在该文件里加入如下内容:
if filereadable("cscope.out")
  cs add cscope.out
endif
这样以后进入Kernel源码打开文件后就可以直接使用:cs f g start_kernel等查找语句了。 
关于ctags,我们在vim的normal模式下使用:tag tagname查找定位tag时可能有好几个,那么我们还可以使用如下指令来定位:
:tfirst    跳转到第一个
:tnext    跳转到下一个
:tlast     跳转到最后一个 
关于cscope,我们使用:cs help可以看到如下帮助信息:
cscope commands: add : Add a new database (Usage: add file|dir [pre-path] [flags]) find : Query for a pattern (Usage: find c|d|e|f|g|i|s|t name) c: Find functions calling this function d: Find functions called by this function e: Find this egrep pattern f: Find this file g: Find this definition i: Find files #including this file s: Find this C symbol t: Find this text string help : Show this message (Usage: help) kill : Kill a connection (Usage: kill #) reset: Reinit all connections (Usage: reset) show : Show connections (Usage: show)
其大概翻译如下:
cscope命令:
add : 添加一个新的cscope数据库
find : 按如下指定模式查找标签
c: 查找调用当前函数的函数
d: 查找被当前函数所调用的函数
e: 查找egrep模式
f: 查找文件
g: 查找定义
i: 查找 #including 这个文件的所有文件
s: 查找C符号
t: 查找字符串
help : 显示帮助信息
kill : 关闭指定连接
reset: 重置所有连接
show : 显示所有连接
从帮助信息可以了解到cscope的主要功能还是用来查找,ctags也是类似功能,不过从使用体验来说,ctags只是简单的查找字符,没有严格看到查找时的分类,所以使用上会先使用cscope查找定位来缩小范围,再使用ctags在小范围内进行定位。这只是简单的补充,还有更多详细、更深的使用技巧等着我们继续挖掘呢! 
参考资料:http://edsionte.com/techblog/archives/1689

评论

此博客中的热门博文

I/O映射之I/O端口

通过Netlink检测网线插拔

使用seq_file