:cs find s ---- 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
:cs find g ---- 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
:cs find d ---- 查找本函数调用的函数
:cs find c ---- 查找调用本函数的函数
:cs find t: ---- 查找指定的字符串
:cs find e ---- 查找egrep模式,相当于egrep功能,但查找速度快多了
:cs find f ---- 查找并打开文件,类似vim的find功能
:cs find i ---- 查找包含本文件的文件
VIM:
H:将光标移到屏幕最上行
M:将光标移到屏幕中间
L:将光标移到屏幕最下面
w:在指定行内右移光标,到下一个字的开头
e: 在指定行内右移光标,到下一个字的末尾
b:在指定行内左移光标,到前一个字的开头
$:右移光标,到本行的末尾
^:移动光标,到本行第一个非空字符
gg:移动到这个文件第一列
.:重复上一个动作
"Generate tags and cscope.out from FileList.txt (c, cpp, h, hpp)
nmap <C-@> :!find -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" > FileList.txt<CR>\ :!ctags -L -< FileList.txt<CR>\ :!cscope -bkq -i FileList.txt<CR>
if has("cscope")set csto=0set nocsverb" add any database in current directoryif filereadable("cscope.out")cs add cscope.outendifset csverb"set cst 这两句会将cscope当作tag,当找不到时会卡住,因此注释掉"set cscopetag
endifnmap zs :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap zg :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap zc :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap zt :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap ze :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap zf :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap zi :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap zd :cs find d <C-R>=expand("<cword>")<CR><CR>
利用 crtl + ] 跳转到定义。
利用 z + c 跳转到调用。
利用 z + t 查找光标所在的字符串出现的所有位置。
利用 crtl + t 跳转回到上次的位置。
至于如何生成该文件,最简单的方法就是使用find命令将所有符合条件的文件列出,重定向到cscope.files中。例如find ./ -name *.c >> cscope.files。当然,也可以写一个简单的shell或者python脚本来生成(末尾提供python脚本源码,在需要生成cscope.files的目录下执行即可)。
有了cscope.files之后,我们运行cscope -bqk即可。这样相对路径的问题就解决了。
配置.vimrc初始化
set tags=..../tags
cs add ...../....../
set number