ctags的功能:掃描指定的源文件,找出其中所包含的語法元素,並將找到的相關內容記錄下來。
1 查看ctags支持的語言
ctags --list-languages
2 查看語言和擴展名的對應關係
ctags --list-maps
3 查看ctags可以識別和記錄的語法元素
ctags --list-kinds
單獨查看可以識別的C++的語法元素:
[chuxing@hostname ~]$ ctags --list-kinds=c++
c classes
d macro definitions
e enumerators (values inside an enumeration)
f function definitions
g enumeration names
l local variables [off]
m class, struct, and union members
n namespaces
p function prototypes [off]
s structure names
t typedefs
u union names
v variable definitions
x external and forward variable declarations [off]
4 對當前目錄下所有ctags支持的語言格式文件生成tags
ctags -R *
缺點很明顯,tags會非常大,tags生成會非常慢,而且代碼跳轉會卡頓。
5 只對特定文件生成tags
ctags `find -name "*.h"`
6 使用tags
6.1 tag
命令
用於跳轉到指定的tag。例如:
tag tagname
使用這個命令可以跳轉到tagname
的定義處,即使它在另一個文件中。
6.2 快捷鍵Ctrl+]
取出當前光標下的word作爲tag的名字並進行跳轉。
6.3 tags
命令
列出曾經訪問過的tag的列表
6.4 快捷鍵Ctrl+T
跳轉到前一次的tag處。
6.5 stag
命令
stag tagname
分割當前窗口,並且跳轉到指定的tag。
6.6 快捷鍵Ctrl+W+]
分割當前窗口,並且跳轉到光標下的tag。
6.7 同名tag
如果存在多個同名的tag,tag命令會給出一個tag的列表,可以通過鍵入tag的序號來選擇tag;也可以通過tselect
來過濾tag,如::tselect tagname
如果要在多個tag間移動,可以使用如下命令:
:tfirst go to first match
:[count]tprevious go to [count] previous match
:[count]tnext go to [count] next match
:tlast go to last match
如果沒有指定[count]
,默認是1。
7 其他
- 如果是多個tags文件,可以通過設置
tags
選項來引入更多的tags文件。例如::set tags=./tags, ./../tags, ./*/tags
- 使用
tag
命令時,可以輸入部分tag名,然後使用Tab
鍵進行補全。
參考來源:
1. https://blog.csdn.net/u011729865/article/details/75452867
2. https://blog.csdn.net/gangyanliang/article/details/6889860