Intelligent Tags


Ⅰ. 插件描述

Vim script to intelligently (and automatically) call ctags

Ⅱ. 基本信息

创建日期:  2011-07-21
使用用户:  1
Github星:  3
插件作者:  Stephen Bell

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'bahejl/intelligent-tags'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'bahejl/intelligent-tags'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'bahejl/intelligent-tags'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/bahejl/intelligent_tags

Ⅳ. 文档说明

Intelligent Tags is designed to handle tag creation for you. Tradionally, you
would run ctags on your project at regular intervals (or in a cron job), but I
struggled with this approach for several reasons:

  • I'm initially not familiar with the project structure of many of the
  • projects I work on, so I have to chase down the includes until I feel
  • comfortable that I know where the project ends/begins. This is a large
  • overhead, and prevents me from using tags when I need them the most: while
  • getting familiar with a project As I actively work on a project, updating
  • the tags once a day, or even every hour, just doesn't cut it. I would like
  • the tags to be updated as soon as the file is updated.

Intelligent Tags solves these problems by using two tools. First, it uses
Vim's built-in options 'include', and 'includeexpr' to determine any/all
included files whose tags should be used. The depth of this 'include search'
can be set by the user to any level, including infinite depth (all includes of
includes of includes, etc) and zero depth (current file only). In order for
this to work properly, Vim's path option must be set correctly. You can check
if it is correct by running the Vim command ':checkpath'. For more
information on setting your path type ':h path'.

The second tool Intelligent Tags uses is exhuberant ctags. Intelligent Tags
uses exhuberant ctags' report of supported languages to add a FileType
autocommand for each type of supported file. I want my tags updated as soon
as I make a change to a file, but if you use the tradional method of having a
single tags file per project that can take quite a while -- especially for a
large project. To work around that problem, Intelligent Tags creates a
seperate tags file for each source file, and only updates those that are out
of date.

This methodolgy begins to break down for some languages, such as C, where the
following problems exist:

  • foo.c includes bar.h, followed by baz.h, so (almost magically) everything in
  • bar.h is available to baz.h. Because Intelligent Tags works on a per-file
  • and not per-project basis, it is impossible (as far as I can tell) for
  • Intelligent Tags to know that bar.h's tags should be included based only on
  • the information in baz.h. foo.c includes bar.h, which contains externals
  • defined in bar.c. Intelligent Tags works around this problem by allowing
  • for a special 'header' option. If this is defined, when Intelligent Tags
  • finds any included file whose extension is recognized as a header, it will
  • search for a source file of the same name and include its tags as well.

In the end, you should be able to open any exhuberant ctags supported file,
and get all of the tags generated for you for free!

添加新评论