vim设置成类source insight功能,实现跳转和查找

高版本的内核代码有脚本可以生成索引,通过vim看代码过程可以实现跳转,具备基本的source insight功能。

1. cd到kernel所在目录,执行如下脚本,生成源码的索引文件
生成ctags的索引文件
[root@localhost]# ./scripts/tags.sh tags

生成cscope的索引文件
[root@localhost]# ./scripts/tags.sh cscope

2. vim 中添加索引文件
随便打开工程下面的一个文件
添加ctags的索引文件:
:set tags=内核代码的目录/tags

添加cscope索引文件:
:cs add 内核代码的目录/cscope.out

3. vim 打开内核的文件,即可跳转
ctags的方法: 光标移动到待跳转的单词上, 按ctrl + ] 即可跳转过去,按ctrl + o 可跳回来;
cscope的方法: vim 敲 :cs help 查找帮助
常用的如下几个:
Find this C symbol:                             cs find s XXX
Find this file:                                       cs find f XXX
Find functions called by this function: cs find d XXX
Find functions calling this function:     cs find c xxx

低版本的内核(比如linux-2.4)可能没有scripts/tags.sh这个文件,可以把高版本的scripts/tags.sh脚本
拷贝到低版本内核中,一样有效果!

猜你喜欢

转载自www.cnblogs.com/samdyhc/p/9301663.html
今日推荐