references
- exuberant ctags: https://ctags.sourceforge.net/
- universal ctags: https://docs.ctags.io/en/latest/index.html
Introduction
what is ctags ?
- 个人人为,ctags是vim使用的必备工具,那么ctags能够干什么呢?它基于C/C++ source files通过创建一个tags文件来实现快速定位:
class names;
macro definitions;
enumeration names;
function definitions;
function prototypes/declarations;
class, interface, struct, and union data members;
structure names;
typedefs;
union names;
variables (definitions and external declarations).
How to install ctags ?
Windows
- 可以通过https://ctags.sourceforge.net/页面获取windows的ctags安装包,安装后将安装路径下的ctgas.exe所在的bin路径添加到windows环境变量中,即可在git for windows等这样的shell环境下使用。
Linux:(以ubuntu为例)
- apt-get install ctags
a. 这样会提示出符合安装条件的ctags类型,exuberant ctags 和 universal ctags;
个人喜好,选择了exuberant ctags;universal ctags是exuberant ctags的继续开发;
How to use ctags?
config
cd <source_code_dir>
ctags -R .
在.vimrc中增加如下行
set tags=tags; "分号不能省略"
usage
- 在利用vim打开一个文件时,将光标移动到需要查询定义的字符串中:
a. “g” + “]” – 跳转至定义;
b. “ctrl” + “t” – 返回到上一次跳转的位置; - 在shell命令下输入:vim -t <string_name> ,可直接打开string_name的定义所在的文件。