- [root@hxy ~]# ctags --version
- Exuberant Ctags 5.6, Copyright (C) 1996-2004 Darren Hiebert
- Compiled: Jul 17 2006, 11:39:49
- Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
- Optional compiled features: +wildcards, +regex
Q. When I try to open the taglist window, I am seeing the following error message. How do I fix this problem? Taglist: Failed to generate tags for /my/path/to/file ctags: illegal option -- -^@usage: ctags [-BFadtuwvx] [-f tagsfile] file ... A. The taglist plugin will work only with the exuberant ctags tool. You cannot use the GNU ctags or the Unix ctags program with the taglist plugin. You will see an error message similar to the one shown above, if you try use a non-exuberant ctags program with Vim. To fix this problem, either add the exuberant ctags tool location to the PATH environment variable or set the 'Tlist_Ctags_Cmd' variable. (版本不对, let Tlist_Ctags_Cmd=”/path/to/exuberant/ctags“,该选项不一定起作用)
- [root@gz hxy]# unzip taglist_45.zip -d /usr/share/vim/vim70
- Archive: taglist_45.zip
- inflating: /usr/share/vim/vim70/plugin/taglist.vim
- inflating: /usr/share/vim/vim70/doc/taglist.txt
- Tlist_GainFocus_On_ToggleOpen : #为1则使用TlistToggle打开标签列表窗口后会获焦点至于标签列表窗口;为0则taglist打开后焦点仍保持在代码窗口
- Tlist_Auto_Open # 为1则Vim启动后自动打开标签列表窗口
- Tlist_Close_On_Select : # 选择标签或文件后是否自动关闭标签列表窗口
- Tlist_Exit_OnlyWindow : #Vim当前仅打开标签列表窗口时,是否自动退出Vim
- Tlist_Use_SingleClick : #是否将默认双击标答打开定义的方式更改为单击后打开标签
- Tlist_Auto_Highlight_Tag : #是否高亮显示当前标签。命令":TlistHighlightTag"也可达到同样效果
- Tlist_Highlight_Tag_On_BufEnter : # 默认情况下,Vim打开/切换至一个新的缓冲区/文件后,标签列表窗口会自动将当前代码窗口对应的标签高亮显示。TlistHighlight_Tag_On_BufEnter置为0可禁止以上行为
- Tlist_Process_File_Always : #为1则即使标签列表窗口未打开,taglist仍然会在后台处理vim所打开文件的标签
- Tlist_Auto_Update : #打开/禁止taglist在打开新文件或修改文件后自动更新标签。禁止自动更新后,taglist仅在使用:TlistUpdate,:TlistAddFiles,或:TlistAddFilesRecursive命令后更新标签
- Tlist_File_Fold_Auto_Close : #自动关闭标签列表窗口中非激活文件/缓冲区所在文档标签树,仅显示当前缓冲区标签树
- Tlist_Sort_Type : #标签排序依据,可以为"name"(按标签名排序)或"order"(按标签在文件中出现的顺序,默认值)
- Tlist_Use_Horiz_Window : #标签列表窗口使用水平分割样式
- Tlist_Use_Right_Window : #标签列表窗口显示在右侧(使用垂直分割样式时)
- Tlist_WinWidth : #设定水平分割时标签列表窗口的宽度
- Tlist_WinHeight : #设定垂直分割时标签列表窗口的高度
- Tlist_Inc_Winwidth : #显示标签列表窗口时允许/禁止扩展Vim窗口宽度
- Tlist_Compact_Format : #减少标签列表窗口中的空白行
- Tlist_Enable_Fold_Column : #是否不显示Vim目录列
- Tlist_Display_Prototype : #是否在标签列表窗口用标签原型替代标签名
- Tlist_Display_Tag_Scope : #在标签名后是否显示标签有效范围
- Tlist_Show_Menu : #在图型界面Vim中,是否以下拉菜单方式显示当前文件中的标签
- Tlist_Max_Submenu_Item : #子菜单项上限值。如子菜单项超出此上限将会被分隔到多个子菜单中。缺省值为25
- Tlist_Max_Tag_Length : #标签菜单中标签长度上限
- cscope --version
- cscope: version 15.5
- [root@gz cscope]# cscope -h
- Usage: cscope [-bcCdehklLqRTuUvV] [-f file] [-F file] [-i file] [-I dir] [-s dir]
- [-p number] [-P path] [-[0-8] pattern] [source files]
- -b Build the cross-reference only.
- -C Ignore letter case when searching.
- -c Use only ASCII characters in the cross-ref file (don't compress).
- -d Do not update the cross-reference.
- -e Suppress the <Ctrl>-e command prompt between files.
- -F symfile Read symbol reference lines from symfile.
- -f reffile Use reffile as cross-ref file name instead of cscope.out.
- -h This help screen.
- -I incdir Look in incdir for any #include files.
- -i namefile Browse through files listed in namefile, instead of cscope.files
- -k Kernel Mode - don't use /usr/include for #include files.
- -L Do a single search with line-oriented output.
- -l Line-oriented interface.
- -num pattern Go to input field num (counting from 0) and find pattern.
- -P path Prepend path to relative file names in pre-built cross-ref file.
- -p n Display the last n file path components.
- -q Build an inverted index for quick symbol searching.
- -R Recurse directories for files.
- -s dir Look in dir for additional source files.
- -T Use only the first eight characters to match against C symbols.
- -U Check file time stamps.
- -u Unconditionally build the cross-reference file.
- -v Be more verbose in line mode.
- -V Print the version number.
- #!/bin/sh
- KERNDIR=/home/hxy/linux-2.6.28_smdk6410
- CS_PRJ=/home/hxy/cscope
- KER_PRJ=$CS_PRJ/linux-2.6.28
- #if [ -ne $KER_PRJ ] ; then
- #mkdir -p $KER_PRJ
- #endif
- find $KERNDIR/mm/* $KERNDIR/init/* \
- $KERNDIR/ipc/* $KERNDIR/net/* $KERNDIR/include/linux/* \
- $KERNDIR/arch/arm/boot/* $KERNDIR/arch/arm/common/* $KERNDIR/arch/arm/include/* \
- $KERNDIR/arch/arm/mach-s3c6410/* $KERNDIR/arch/arm/mach-s3c6410/* $KERNDIR/arch/arm/plat-s3c64xx/* \
- $KERNDIR/arch/arm/mm/* $KERNDIR/arch/arm/plat-s3c/* \
- -name "*.[chxsS]" >$KER_PRJ/cscope.files
- cd $KER_PRJ
- cscope -b -q -k
- cd $CS_PRJ
- if has("cscope") && filereadable("/usr/bin/cscope")
- set csprg=/usr/bin/cscope
- set csto=0
- set cst
- set nocsverb
- " add any database in current directory
- if filereadable("cscope.out")
- cs add cscope.out
- " else add database pointed to by environment
- elseif $CSCOPE_DB != ""
- cs add $CSCOPE_DB
- endif
- cs add /home/hxy/cscope/linux-2.6.28/cscope.out
- set csverb
- endif
- : 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 + cscope/ctags,就可以实现SourceInsight的功能,以后可以不再用盗版SouceInsight读代码了。
按照vim里cscope的参考手册(在vim中执行”:help cscope”命令),把cscope功能加到.vimrc里后(需要你的vim在编译时选择了”–enable-cscope”选项,否则你需要重新编译vim),配置就算完成了。然后用下面的命令生成代码的符号索引文件:
这个命令会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。
其中cscope.out是基本的符号索引,后两个文件是使用”-q”选项生成的,可以加快cscope的索引速度。
上面所用到的命令参数,含义如下:




接下来,就可以在vim里读代码了。
不过在使用过程中,发现无法找到C++的类、函数定义、调用关系。仔细阅读了cscope的手册后发现,原来cscope在产生索引文件时,只搜索类型为C, lex和yacc的文件(后缀名为.c, .h, .l, .y),C++的文件根本没有生成索引。不过按照手册上的说明,cscope支持c++和Java语言的文件。
于是按照cscope手册上提供的方法,先产生一个文件列表,然后让cscope为这个列表中的每个文件都生成索引。
为了方便使用,编写了下面的脚本来更新cscope和ctags的索引文件:
#!/bin/sh
find . -name "*.h" -o -name "*.c"-o -name "*.cc" > cscope.files
cscope -bkq -i cscope.files
ctags -R
这个脚本,首先使用find命令,查找当前目录及子目录中所有后缀名为”.h”, “.c”和”.cc”的文件,并把查找结果重定向到文件cscope.files中。
然后cscope根据cscope.files中的所有文件,生成符号索引文件。
最后一条命令使用ctags命令,生成一个tags文件,在vim中执行”:help tags”命令查询它的用法。它可以和cscope一起使用
遇到错误:
cscope error reading cscope connection
解决: 先使用”:cs kill 0″断开和cscope的连接,然后再”:cs add cscope.out”重新连就可以了。