vim - 怎样用ctags为glibc的头文件生成tags?

浏览:63日期:2023-07-24

问题描述

what i want:

想要在vim中用omnicompletion或者omnicppcompletion的功能,实现对glibc函数的自动补齐,比如在C源文件中输入pri,然后按C-x C-o能够弹出列表补齐printf,诸如此类。现在的问题是,我用ctags对glibc-headers-2.15-57.fc17.i686安装的标准C头文件进行处理,生成tags_glibc文件。但是在C源文件中输入pri,然后C-x C-o,弹出的菜单里面,只有stdio2.h中的printf的定义和原型声明,而没有stdio.h的printf声明。令人奇怪的是,我用vim查看生成的tags文件,搜索printf,发现有如下三条entry:

printf/usr/include/bits/stdio2.h/^printf (__const char *__restrict __fmt, ...)$/;'fprintf/usr/include/bits/stdio2.h108;'dprintf/usr/include/stdio.h/^extern int printf (__const char *__restrict __format, ...);$/;'p

最后一条表明ctags的确生成stdio.h中的printf的原型声明(类型为p),但是为什么我在insert模式下,输入pri<C-x C-o>,却看不见第三条呢?我错在哪里了??fprintf(stdio.h,stdio2.h中都有该符号),memcpy(string.h,string3.h中都有)等函数也出现了同样的现象。

环境

我的系统是fedora17(3.6.3-1.fc17.i686),ctags是最新版,5.8的用的ctags命令如下:

ctags --langmap=c:.c.h --language-force=c -h .h --c-kinds=+pxl --exclude=’tags*’ --exclude=’*swp’ --exclude=’*~’ --exclude=’*[!ch]’ -I _THROW -I __attribute__+ -I __wur -f tags_glibc -L glibc-headers-filelist.txt

其中,glibc-headers-filelist.txt的生成是如下命令:

rpm -ql glibc-headers |grep ’.h’ >glibc-headers-filelist.txt问题

各位vim高手,请问有没有办法能够比较好地生成glibc头文件的tags文件

问题解答

回答1:

-eInclude extern tags. ctags will normally ignore extern declarations of functions or variables; that’s handy when generating tags for your own programs. A tags file for the extern declarations in the system’s standard header files can be a very handy resource, so this -e flag was created.

From http://elvis.the-little-red-haired-gi...

回答2:

使用tags文件时,需要在tags所在的目录打开vim。

不同目录时需要在vim里设置tags变量,变量值为tags文件路径。例如:

:set tags=....../tags_glibc

相关文章: