URL:         http://www.math.fu-berlin.de/~guckes/vim/tags.html
URL:         https://www.vim8.org/tags.html (mirror)
Created:     Tue Mar 10 00:00:00 CET 1998
Last update: Tue Mar 10 16:38:40 CET 1998

VIM and Tags

Vim makes use of "tags" for finding the helptext to some topic.

But what is a tag exactly? How does it work? How can you make use of this?

Let me explian about the "traditional tags" for use with Vi first:


Vi and Tags

Definition: A "tag" is some text which points to other text.

In this respect a tag is like a bookmark, pointer, or reference, ie it gives the location of some other text in some other file.

Definition: A "tags file" is a file which contains a tag on each line. [I am not sure whether comment lines are allowed, though.]

So a tags file is more or less an index of some program which allows to find the definition of its parts, eg data type definitions, functions, macros, variables.

Disadvantages of standard tags

No Column Position
You cannot specify the location of the tagname within a line.

Only Single-Word Names
You cannot search for tagnames which contain a non-word letter, usually spaces. So you cannot use "up-to-date" as a tagname.

No Overloading
Some languages allow "overloading" of a name, ie depending on the context, eg a name can be both the name of a variable of function. This is used very often for operators such as '+' or '-' to allow addition and subsctration for numbers as well as for sets. This leads to more than one definition for a name/object/tagname - but Vi will just use the first tag match it can find.

This naturally asks for an extension to the functionality of tags, of course. As tags should be possible to use for more than just the language C and with many more programs, the definition of the "tags file format" has to be expanded to allow for more functionality. There is some work going on for this already.

Some vi clones (elvis, vile, and vim) provide several enhancements already. Vim already finds all matches and allow to move to the next or previous match.


Emacs, Vi and its clones make use of a tags file to quickly find the definition of "objects" within the source files to a program. Change of the source also requires an update of the tags file, of course.

The generation of a tags file was usually done with the program "ctags", short for "Create TAGS file". Unfortunately, this program could just be used with the language 'C' - but not for C++ or Java.

So Darren Hiebert wrote another "ctags" program which is now capable of generating a tags file for source code in C++ and Java.


The :tag command

The command ":tag tagname" will make Vi (this includes Vim, too) jump to the position that the tagname points to. Usually the tagname is found in the text itself, so instead of copying the tagname onto the command line you can use the command '^]' when the cursor in on the tagname. This is much quicker, of course.

There are some more commands that deals with tags. More about this later.

Every tagname that gets used with a "tag command" is pushed onto a stack, ie it is remembered in a "last in - first out" (LIFO) structure. This allows to reuse the tagnames, eg to jump back to the last used tagname. With Vim this command is '^T'.

Vim uses tags to allow quick access to other helptexts in the helpfiles. One of the many improvements of Vim over Vi is that Vim has commands to show the "tag stack" together with the associated filenames, as well as showing the current tagname.

Example: Add some tags to the tag stack by entering some help commands� eg ":help www" and ":help news". Then enter ":tags" to show the tag stack:

	:tags
	  # TO tag         FROM line  in file
	  1  1 www                95  tagsearch.txt
	  2  1 news               50  -current-
	>
Unfortunately this command does not show the name of the current file, but simply "-current-". Yp Note: When jumping back to an older tagname with
Send feedback on this page to
Sven Guckes [email protected]