[gutentags_plus] Vim 中使用 gtags 的正确方法

2018-05-22 12:57:30 +08:00
 skywind3000

GNU Global / Gtags 支持 50+ 种编程语言,可以在没有 LSP 或者 LSP 支持不到位的时候为 50+ 种语言提供准确的定义 /引用查找。

插件地址:

https://github.com/skywind3000/gutentags_plus

插件说明:

Gutentags 提供了后台无缝更新 gtags 数据库的功能,而 gutentags_plus 提供了无缝切换 gtags 数据库的功能:

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

9912 次点击
所在节点    Vim
5 条回复
Yggdroot
2018-05-24 17:43:48 +08:00
还没用过 gtags,相对于 ctags 有什么不同和优势?
SpaceVim
2018-05-25 11:28:22 +08:00
ctags 不支持查引用,只能查定义处
skywind3000
2018-05-25 12:20:36 +08:00
@Yggdroot gtags 可以用来搜索引用,ctags 只能查定义。
ivechan
2018-06-24 12:08:49 +08:00
尝试使用 gtags,目前感觉良好。
xiaocang
2019-01-09 15:27:31 +08:00
麻烦请教一下,使用该插件,可以在头文件中搜索相关函数吗。如 `#include <sys/socket.h>` 中的 `socket` 函数

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/456788

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX