30.28 Keep Track of Functions and Included Files with ctags and tags
The source code for a large C program will usually be spread
over several files. Sometimes, it is difficult to keep track of
which file contains which function definitions. To simplify
matters, a UNIX command called ctags
can be used together
with the ctags creates an information file (a database) that vi uses later to determine which files define which functions. By default, this database file is called tags . This file contains lines of the form:
where From within vi , a command such as:
creates a file named tags under your current directory. tags is a database containing information on the functions defined in file.c . A command like:
creates a tags file describing all the C source files under the directory. [If you'll be using the tags file while you're in some other directory, be sure to use an absolute pathname, like this:
That will store absolute pathnames (14.2 ) in the tags file. -JP ] Now suppose your tags file contains information on all the source files that make up a C program. Also suppose that you want to look at or edit a function in the program but do not know where the function is. From within vi , the command:
will look at the tags
file to find out which file contains the
definition of the function name
.
It will then read in the file and position
the cursor on the line where the name is defined. In this way,
you don't have to know which file you have to edit; you only have
to decide which function you want to edit.
[My favorite tags
shortcut is to put the cursor on the first letter of a
function name in your buffer.
Then press CTRL-
- from O'Reilly & Associates' Learning the vi Editor , Chapter 7 |
|