GNU Global / Gtags 支持 50+ 种编程语言,可以在没有 LSP 或者 LSP 支持不到位的时候为 50+ 种语言提供准确的定义 /引用查找。
插件地址:
https://github.om/skywind3000/gutentags_plus
插件说明:
Gutentags 提供了后台无缝更新 gtags 数据库的功能,而 gutentags_plus 提供了无缝切换 gtags 数据库的功能:
GscopeFind
命令,使用 cscope 接口,通过 gtags-cscope 程序进行符号搜索。Gutentags 也提供自动链接 gtags 数据库的功能,但是它会把当前编辑的所有项目的数据库全部添加到 vim 的 cscope 接口中,那么我同时打开多个工程时,查询一个符号,会得到来自所有工程的结果,基本没法看了。所以搜索前必须断开非当前项目的 gtags 数据库链接。
将 gutentags 搭配 gutentags_plus 一起使用,前者提供 gtags 数据库的无缝更新,后者提供数据库无缝切换。使用的时候你只管在任何时候查询符号的定义和引用即可,数据库的更新和切换对你来说完全透明,再也不用操心了,就和使用其他 IDE 一样。
使用方法:
Plug 'ludovicchabant/vim-gutentags' Plug 'skywind3000/gutentags_plus' " enable gtags module let g:gutentags_modules = ['ctags', 'gtags_cscope'] " config project root markers. let g:gutentags_project_root = ['.root'] " generate datebases in my cache directory, prevent gtags files polluting my project let g:gutentags_cache_dir = expand('~/.cache/tags') " forbid gutentags adding gtags databases let g:gutentags_auto_add_gtags_cscope = 0
命令说明:
:GscopeFind {querytype} {name}
通过 cscope 接口操纵 gtags-cscope 程序进行符号查询,并且在查询前处理好数据库切换问题,只保持当前项目的数据库。
{querytype}
corresponds to the actual cscope line interface numbers as well as default nvi commands:
0 or s: Find this symbol 1 or g: Find this definition 2 or d: Find functions called by this function 3 or c: Find functions calling this function 4 or t: Find this text string 6 or e: Find this egrep pattern 7 or f: Find this file 8 or i: Find files #including this file 9 or a: Find places where this symbol is assigned a value
详细见 github README
![]() | 1 Yggdroot 2018-05-24 17:43:48 +08:00 还没用过 gtags,相对于 ctags 有什么不同和优势? |
2 nG29DOMuRYTWfcSr 2018-05-25 11:28:22 +08:00 via Android ctags 不支持查引用,只能查定义处 |
![]() | 3 skywind3000 OP @Yggdroot gtags 可以用来搜索引用,ctags 只能查定义。 |
4 ivechan 2018-06-24 12:08:49 +08:00 尝试使用 gtags,目前感觉良好。 |
5 xiaocang 2019-01-09 15:27:31 +08:00 麻烦请教一下,使用该插件,可以在头文件中搜索相关函数吗。如 `#include <sys/socket.h>` 中的 `socket` 函数 |