Using ctags to find functions

http://www.x.org/wiki/Development/Documentation/UsingCtags/

Finding functions in X is hard. One way to search for the actual definition of a data type is to grep the source directory and then open the file. This can take forever, especially when you don't quite know where to look for.

However, vim's support for ctags makes it easier. It is possible to create a tags file for the whole system and then just use it from within vim. That way, in vim you only have to go to the occurence of the data type, press CTRL+] and it will open the matching definition. With CTRL+T you jump back to the original file.

I created my tags file somewhere in my .vim directory.

$> mkdir .vim/tags/
$> cd .vim/tags/
$> ctags -R /usr/include/* /path/to/X/source/code

ctags will create a file "tags" in the current directory ($HOME/.vim/tags in this case). This way I got pretty much all defintions I need at the moment.

Now you need to tell vim to include this file. Add the following line to your $HOME/.vimrc.

set tags=./tags,tags,/home/username/.vim/tags/tags

On your next startup of vim, everything will be available with CTRL+]. If you use tags heavily, you will find CTRL+G helpful. It shows the name of the file in the current buffer.

A recommendation is to write a little script to update your ctags and run it as a cron job every night. Your computer will not be very responsive while recursively searching for ctags in a multi-GB directory.

Warning

This can be a hazardous setup as the ctags are absolute. If you are working on two different source trees (i.e. two releases of the same software), using CTRL+ ] will jump to the functions as defined in ctags. So you might be editing the wrong source tree.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值