如何在Vim中使用ctags?之前在《把Vim打造成真正的IDE》系列里已经讲过大致的ctags在vim中的使用,这篇文章我们就详细的讲一下。
ctags
(1)到http://ctags.sourceforge.net/下载ctags源码ctags-5.6.tar.gz
http://prdownloads.sourceforge.net/ctags/ctags-5.6.tar.gz
(2)解压并安装
tar zxvf ctags-5.6.tar.gz
cd ctags-5.6
./configure && make && make install
ctags -R *
C-]
- go to definition
C-T
- Jump back from the definition.
C-W C-]
- Open the definition in a horizontal split
Add these lines in vimrc
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
C-\
- Open the definition in a new tab
A-]
- Open the definition in a vertical split
After the tags are generated. You can use the following keys to tag into and tag out of functions:
Ctrl-Left_MouseClick
- Go to definition
Ctrl-Right_MouseClick
- Jump back from definition
<CR> 跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
o 在一个新打开的窗口中显示光标下tag
<Space> 显示光标下tag的原型定义
u 更新taglist窗口中的tag
s 更改排序方式,在按名字排序和按出现顺序排序间切换
x taglist窗口放大和缩小,方便查看较长的tag
+ 打开一个折叠,同zo
- 将tag折叠起来,同zc
* 打开所有的折叠,同zR
= 将所有tag折叠起来,同zM
[[ 跳到前一个文件
]] 跳到后一个文件
q 关闭taglist窗口
<F1> 显示帮助