ctags(1

ctags – Generate tag files for source code

ctags[options] [file(s)]etags[options] [file(s)]Description

Thectagsandetagsprograms (hereinafter collectively referred to asctags, except where distinguished) generate an index (or tag) file for a variety of language objects found infile(s). This tag file allows these items to be quickly and easily located by a text editor or other utility. A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object).

Alternatively,ctagscan generate a cross reference file which lists, in human readable form, information about the various source objects found in a set of language files.

Tag index files are supported by numerous editors, which allow the user to locate the object associated with a name appearing in a source file and jump to the file and line which defines the name. Those known about at the time of this release are:vi(1) and its derivatives (e.g. Elvis, Vim, Vile, Lemmy),CRiSP,Emacs,FTE(Folding Text Editor),JED,jEdit,Mined,NEdit(Nirvana Edit),TSE(The SemWare Editor),UltraEdit,WorkSpace,X2,ZeusCtagsis capable of generating different kinds of tags for each of many different languages. For a complete list of supported languages, the names by which they are recognized, and the kinds of tags which are generated for each, see the–list-languagesand–list-kindsoptions.Source Files

Unless the–language-forceoption is specified, the language of each source file is automatically selected based upon a mapping of file names to languages. The mappings in effect for each language may be display using the–list-mapsoption and may be changed using the–langmapoption. On platforms which support it, if the name of a file is not mapped to a language and the file is executable, the first line of the file is checked to see if the file is a ! script for a recognized language.

By default, all other files names are ignored. This permits runningctagson all files in either a single directory (e.g. ctags *), or on all files in an entire source directory tree (e.g. ctags -R), since only those files whose names are mapped to languages will be scanned.

[The reason that .h extensions are mapped to C++ files rather than C files is because it is common to use .h extensions in C++, and no harm results in treating them as C++ files.]Options

Despite the wealth of available options, defaults are set so thatctagsis most commonly executed without any options (e.g. ctags *, or ctags -R), which will create a tag file in the current directory for all recognized source files. The options described below are provided merely to allow custom tailoring to meet special needs.

Note that spaces separating the single-letter options from their parameters are optional.

Note also that the boolean parameters to the long form options (those beginning with — and that take a[=yesno]parameter) may be omitted, in which case=yesis implied. (e.g.–sortis equivalent to–sort=yes). Note further that =1and =onare considered synonyms for =yes, and that =0and =offare considered synonyms for =no.

Some options are either ignored or useful only when used while running in etags mode (see-eoption). Such options will be noted.

Most options may appear anywhere on the command line, affecting only those files which follow the option. A few options, however, must appear before the first file name and will be noted as such.

Options taking language names will accept those names in either upper or lower case. See the–list-languagesoption for a complete list of the built-in language names.-a

Use backward searching patterns (e.g. ?pattern?). [Ignored in etags mode]

Enable etags mode, which will create a tag file for use with the Emacs editor. Alternatively, ifctagsis invoked by a name containing the string etags (either by renaming, or creating a link to, the executable), etags mode will be enabled. This option must appear before the first file name.-ftagfileUse the name specified bytagfilefor the tag file (default is tags, or TAGS when running in etags mode). Iftagfileis specified as -, then the tag file is written to standard output instead.Ctagswill stubbornly refuse to take orders iftagfileexists and its first line contains something other than a valid tags line. This will save your neck if you mistakenly type ctags -f *.c, which would otherwise overwrite your first C file with the tags generated by the rest! It will also refuse to accept a multi-character file name which begins with a – (dash) character, since this most likely means that you left out the tag file name and this option tried to grab the next option as the file name. If you really want to name your output tag file -ugly, specify it as ./-ugly. This option must appear before the first file name. If this option is specified more than once, only the last will apply.-F

Use forward searching patterns (e.g. /pattern/) (default). [Ignored in etags mode]-hlistSpecifies a list of file extensions, separated by periods, which are to be interpreted as include (or header) files. To indicate files having no extension, use a period not followed by a non-period character (e.g. ., ..x, .x.). This option only affects how the scoping of a particular kinds of tags is interpreted (i.e. whether or not they are considered as globally visible or visible only within the file in which they are defined); it does not map the extension to any particular language. Any tag which is located in a non-include file and cannot be seen (e.g. linked to) from another file is considered to have file-limited (e.g. static) scope. No kind of tag appearing in an include file will be considered to have file-limited scope. If the first character in the list is a plus sign, then the extensions in the list will be appended to the current list; otherwise, the list will replace the current list. See, also, the–file-scopeoption. The default list is c.def. To restore the default list, specify-hdefault. Note that if an extension supplied to this option is not already mapped to a particular language (seeSOURCE FILES, above), you will also need to use either the–langmapor–language-forceoption.-Iidentifier-listSpecifies a list of identifiers which are to be specially handled while parsing C and C++ source files. This option is specifically provided to handle special cases arising through the use of preprocessor macros. When the identifiers listed are simple identifiers, these identifiers will be ignored during parsing of the source files. If an identifier is suffixed with a + character,ctagswill also ignore any parenthesis-enclosed argument list which may immediately follow the identifier in the source files. If two identifiers are separated with the = character, the first identifiers is replaced by the second identifiers for parsing purposes. The list of identifiers may be supplied directly on the command line or read in from a separate file. If the first character ofidentifier-listis @, . or a pathname separator (/ or \), or the first two characters specify a drive letter (e.g. C:), the parameteridentifier-listwill be interpreted as a filename from which to read a list of identifiers, one per input line. Otherwise,identifier-listis a list of identifiers (or identifier pairs) to be specially handled, each delimited by a either a comma or by white space (in which case the list should be quoted to keep the entire list as one command line argument). Multiple-Ioptions may be supplied. To clear the list of ignore identifiers, supply a single dash (-) foridentifier-list.

This feature is useful when preprocessor macros are used in such a way that they cause syntactic confusion due to their presence. Indeed, this is the best way of working around a number of problems caused by the presence of syntax-busting macros in source files (seeCAVEATS, below). Some examples will illustrate this point.int foo ARGDECL4(void *, ptr, long int, nbytes)In the above example, the macro ARGDECL4 would be mistakenly interpreted to be the name of the function instead of the correct name of foo. Specifying-IARGDECL4results in the correct behavior./* creates an RCS version string in module */

MODULE_VERSION($Revision: 690 $)In the above example the macro invocation looks too much like a function definition because it is not followed by a semicolon (indeed, it could even be followed by a global variable definition that would look much like a K&R style function parameter declaration). In fact, this seeming function definition could possibly even cause the rest of the file to be skipped over while trying to complete the definition. Specifying-IMODULE_VERSION+would avoid such a problem.CLASS Example

;The example above uses CLASS as a preprocessor macro which expands to something different for each platform. For instance CLASS may be defined as class __declspec(dllexport) on Win32 platforms and simply class on UNIX. Normally, the absence of the C++ keyword class would cause the source file to be incorrectly parsed. Correct behavior can be restored by specifying-ICLASS=class.-LfileRead fromfilea list of file names for which tags should be generated. Iffileis specified as -, then file names are read from standard input. File names read using this option are processed following file names appearing on the command line. Options are also accepted in this input. If this option is specified more than once, only the last will apply.Note:fileis read in line-oriented mode, where a new line is the only delimiter and non-trailing white space is considered significant, in order that file names containing spaces may be supplied (however, trailing white space is stripped from lines); this can affect how options are parsed if included in the input.-n

Equivalent to–excmd=pattern.-otagfileEquivalent to-ftagfile.-R

Equivalent to–sort=no(i.e. unsorted).

This option is silently ignored for backward-compatibility with the ctags of SVR4 Unix.

Print a tabular, human-readable cross reference (xref) file to standard output instead of generating a tag file. The information contained in the output includes: the tag name; the kind of tag; the line number, file name, and source line (with extra white space condensed) of the file which defines the tag. No tag file is written and all options affecting tag file output will be ignored. Example applications for this feature are generating a listing of all functions located in a source file (e.g.ctags -x –c-kinds=f file), or generating a list of all externally visible global variables located in a source file (e.g.ctags -x –c-kinds=v–file-scope=no file). This option must appear before the first file name.–append[=yesno]Indicates whether tags generated from the specified files should be appended to those already present in the tag file or should replace them. This option is off by default. This option must appear before the first file name.–etags-include=fileInclude a reference tofilein the tag file. This option may be specified as many times as desired. This supports Emacs capability to use a tag file which includes other tag files. [Available only in etags mode]–exclude=[pattern]Addpatternto a list of excluded files and directories. This option may be specified as many times as desired. For each file name considered byctags, eachpatternspecified using this option will be compared against both the complete path (e.g. some/path/base.ext) and the base name (e.g. base.ext) of the file, thus allowing patterns which match a given file name irrespective of its path, or match only a specific path. If appropriate support is available from the runtime library of your C compiler, thenpatternmay contain the usual shell wildcards (not regular expressions) common on Unix (be sure to quote the option parameter to protect the wildcards from being expanded by the shell before being passed toctags; also be aware that wildcards can match the slash character, /). You can determine if shell wildcards are available on your platform by examining the output of the–versionoption, which will include +wildcards in the compiled feature list; otherwise,patternis matched against file names using a simple textual comparison.

Ifpatternbegins with the character @, then the rest of the string is interpreted as a file name from which to read exclusion patterns, one per line. Ifpatternis empty, the list of excluded patterns is cleared. Note that at program startup, the default exclude list contains EIFGEN, SCCS, RCS, and CVS, which are names of directories for which it is generally not desirable to descend while processing the–recurseoption.–excmd=typeDetermines the type of EX command used to locate tags in the source file. [Ignored in etags mode]

The valid values fortype(either the entire word or the first letter is accepted) are:number

Use only line numbers in the tag file for locating tags. This has four advantages:

Significantly reduces the size of the resulting tag file.

Eliminates failures to find tags because the line defining the tag has changed, causing the pattern match to fail (note that some editors, such asvim, are able to recover in many such instances).

Eliminates finding identical matching, but incorrect, source lines (seeBUGS, below).

Retains separate entries in the tag file for lines which are identical in content. Inpatternmode, duplicate entries are dropped because the search patterns they generate are identical, making the duplicate entries useless.

However, this option has one significant drawback: changes to the source files can cause the line numbers recorded in the tag file to no longer correspond to the lines in the source file, causing jumps to some tags to miss the target definition by one or more lines. Basically, this option is best used when the source code to which it is applied is not subject to change. Selecting this option type causes the following options to be ignored:-BF.pattern

Use only search patterns for all tags, rather than the line numbers usually used for macro definitions. This has the advantage of not referencing obsolete line numbers when lines have been added or removed since the tag file was generated.

In this mode, patterns are generally used with a few exceptions. For C, line numbers are used for macro definition tags. This was the default format generated by the originalctagsand is, therefore, retained as the default for this option. For Fortran, line numbers are used for common blocks because their corresponding source lines are generally identical, making pattern searches useless for finding all matches.–extra=[+-]flagsSpecifies whether to include extra tag entries for certain kinds of information. The parameterflagsis a set of one-letter flags, each representing one kind of extra tag entry to include in the tag file. Ifflagsis preceded by by either the + or – character, the effect of each flag is added to, or removed from, those currently enabled; otherwise the flags replace any current settings. The meaning of each flag is as follows:f

Include an entry for the base file name of every source file (e.g. example.c), which addresses the first line of the file.

Include an extra class-qualified tag entry for each tag which is a member of a class (for languages for which this information is extracted; currently C++, Eiffel, and Java). The actual form of the qualified tag depends upon the language from which the tag was derived (using a form that is most natural for how qualified calls are specified in the language). For C++, it is in the form class::member; for Eiffel and Java, it is in the form mber. This may allow easier location of a specific tags when multiple occurrences of a tag name occur in the tag file. Note, however, that this could potentially more than double the size of the tag file.–fields=[+-]flagsSpecifies the available extension fields which are to be included in the entries of the tag file (seeTAG FILE FORMAT, below, for more information). The parameterflagsis a set of one-letter flags, each representing one type of extension field to include, with the following meanings (disabled by default unless indicated):a

Kind of tag as a single letter [enabled]

Language of source file containing tag

Signature of routine (e.g. prototype or parameter list)

Type and name of a variable or typedef as typeref: field [enabled]Each letter or group of letters may be preceded by either + to add it to the default set, or – to exclude it. In the absence of any preceding + or – sign, only those kinds explicitly listed inflagswill be included in the output (i.e. overriding the default set). This option is ignored if the option–format=1has been specified. The default value of this option isfkst.–file-scope[=yesno]Indicates whether tags scoped only for a single file (i.e. tags which cannot be seen outside of the file in which they are defined, such as static tags) should be included in the output. See, also, the-hoption. This option is enabled by default.–filter[=yesno]Causesctagsto behave as a filter, reading source file names from standard input and printing their tags to standard output on a file-by-file basis. If–sortedis enabled, tags are sorted only within the source file in which they are defined. File names are read from standard input in line-oriented input mode (see note for-Loption) and only after file names listed on the command line or from any file supplied using the-Loption. When this option is enabled, the options-f,-o, and–totalsare ignored. This option is quite esoteric and is disabled by default. This option must appear before the first file name.–filter-terminator=stringSpecifies a string to print to standard output following the tags for each file name parsed when the–filteroption is enabled. This may permit an application reading the output of ctags to determine when the output for each file is finished. Note that if the file name read is a directory and–recurseis enabled, this string will be printed only one once at the end of all tags found for by descending the directory. This string will always be separated from the last tag line for the file by its terminating newline. This option is quite esoteric and is empty by default. This option must appear before the first file name.–format=levelChange the format of the output tag file. Currently the only valid values forlevelare1or2. Level 1 specifies the original tag file format and level 2 specifies a new extended format containing extension fields (but in a manner which retains backward-compatibility with originalvi(1) implementations). The default level is 2. This option must appear before the first file name. [Ignored in etags mode]–helpPrints to standard output a detailed usage description, and then exits.–if0[=yesno]Indicates a preference as to whether code within an if 0 branch of a preprocessor conditional should be examined for non-macro tags (macro tags are always included). Because the intent of this construct is to disable code, the default value of this option isno. Note that this indicates a preference only and does not guarantee skipping code within an if 0 branch, since the fall-back algorithm used to generate tags when preprocessor conditionals are too complex follows all branches of a conditional. This option is disabled by default.–LANG-kinds=[+-]kindsSpecifies a list of language-specific kinds of tags (or kinds) to include in the output file for a particular language, whereLANGis case-insensitive and is one of the built-in language names (see the–list-languagesoption for a complete list). The parameterkindsis a group of one-letter flags designating kinds of tags (particular to the language) to either include or exclude from the output. The specific sets of flags recognized for each language, their meanings and defaults may be list using the–list-kindsoption. Each letter or group of letters may be preceded by either + to add it to, or – to remove it from, the default set. In the absence of any preceding + or – sign, only those kinds explicitly listed inkindswill be included in the output (i.e. overriding the default for the specified language).

As an example for the C language, in order to add prototypes and external variable declarations to the default set of tag kinds, but exclude macros, use–c-kinds=+px-d; to include only tags for functions, use–c-kinds=f.–langdef=nameDefines a new user-defined language,name, to be parsed with regular expressions. Once defined,namemay be used in other options taking language names. The typical use of this option is to first define the language, then map file names to it using–langmap, then specify regular expressions using–regex-LANGto define how its tags are found.–langmap=map[,map[…]]Controls how file names are mapped to languages (see the–list-mapsoption). Each comma-separatedmapconsists of the language name (either a built-in or user-defined language), a colon, and a list of file extensions and/or file name patterns. A file extension is specified by preceding the extension with a period (e.g. .c). A file name pattern is specified by enclosing the pattern in parentheses (e.g. ([Mm]akefile)). If appropriate support is available from the runtime library of your C compiler, then the file name pattern may contain the usual shell wildcards common on Unix (be sure to quote the option parameter to protect the wildcards from being expanded by the shell before being passed toctags). You can determine if shell wildcards are available on your platform by examining the output of the–versionoption, which will include +wildcards in the compiled feature list; otherwise, the file name patterns are matched against file names using a simple textual comparison. When mapping a file extension, it will first be unmapped from any other languages.

If the first character in a map is a plus sign, then the extensions and file name patterns in that map will be appended to the current map for that language; otherwise, the map will replace the current map. For example, to specify that only files with extensions of .c and .x are to be treated as C language files, use–langmap=c:.c.x; to also add files with extensions of .j as Java language files, specify–langmap=c:.c.x,java:+.j. To map makefiles (e.g. files named either Makefile, makefile, or having the extension .mak) to a language called make, specify–langmap=make:([Mm]akefile).mak. To map files having no extension, specify a period not followed by a non-period character (e.g. ., ..x, .x.). To clear the mapping for a particular language (thus inhibiting automatic generation of tags for that language), specify an empty extension list (e.g.–langmap=fortran:). To restore the default language mappings for all a particular language, supply the keyword default for the mapping. To specify restore the default language mappings for all languages, specify–langmap=default. Note that file extensions are tested before file name patterns when inferring the language of a file.–language-force=languageBy default,ctagsautomatically selects the language of a source file, ignoring those files whose language cannot be determined (seeSOURCE FILES, above). This option forces the specifiedlanguage(case-insensitive; either built-in or user-defined) to be used for every supplied file instead of automatically selecting the language based upon its extension. In addition, the special valueautoindicates that the language should be automatically selected (which effectively disables this option).–languages=[+-]listSpecifies the languages for which tag generation is enabled, withlistcontaining a comma-separated list of language names (case-insensitive; either built-in or user-defined). If the first language oflistis not preceded by either a + or -, the current list will be cleared before adding or removing the languages inlist. Until a – is encountered, each language in the list will be added to the current list. As either the + or – is encountered in the list, the languages following it are added or removed from the current list, respectively. Thus, it becomes simple to replace the current list with a new one, or to add or remove languages from the current list. The actual list of files for which tags will be generated depends upon the language extension mapping in effect (see the–langmapoption). Note that all languages, including user-defined languages are enabled unless explicitly disabled using this option. Language names included inlistmay be any built-in language or one previously defined with–langdef. The default is all, which is also accepted as a valid argument. See the–list-languagesoption for a complete list of the built-in language names.–licensePrints a summary of the software license to standard output, and then exits.–line-directives[=yesno]Specifies whether line directives should be recognized. These are present in the output of preprocessors and contain the line number, and possibly the file name, of the original sourcefile(s) from which the preprocessor output file was generated. When enabled, this option will causectagsto generate tag entries marked with the file names and line numbers of their locations original sourcefile(s), instead of their actual locations in the preprocessor output. The actual file names placed into the tag file will have the same leading path components as the preprocessor output file, since it is assumed that the original source files are located relative to the preprocessor output file (unless, of course, the line directive specifies an absolute path). This option is off by default.Note:This option is generally only useful when used together with the–excmd=number(-n) option. Also, you may have to use either the–langmapor–language-forceoption if the extension of the preprocessor output file is not known toctags.–links[=yesno]Indicates whether symbolic links (if supported) should be followed. When disabled, symbolic links are ignored. This option is on by default.–list-kinds[=languageall]Lists the tag kinds recognized for either the specified language or all languages, and then exits. Each kind of tag recorded in the tag file is represented by a one-letter flag, which is also used to filter the tags placed into the output through use of the–LANG-kindsoption. Note that some languages and/or tag kinds may be implemented using regular expressions and may not be available if regex support is not compiled intoctags(see the–regex-LANGoption). Each kind listed is enabled unless followed by [off].–list-maps[=languageall]Lists the file extensions and file name patterns which associate a file name with a language for either the specified language or all languages, and then exits. See the–langmapoption, andSOURCE FILES, above.–list-languagesLists the names of the languages understood byctags, and then exits. These language names are case insensitive and may be used in the–language-force,–languages,–LANG-kinds, and–regex-LANGoptions.–options=fileRead additional options fromfile. The file should contain one option per line. As a special case, if–options=NONEis specified as the first option on the command line, it will disable the automatic reading of any configuration options from either a file or the environment (seeFILES).–recurse[=yesno]Recurse into directories encountered in the list of supplied files. If the list of supplied files is empty and no file list is specified with the-Loption, then the current directory (i.e. .) is assumed. Symbolic links are followed. If you dont like these behaviors, either explicitly specify the files or pipe the output offind(1) intoctags -L-instead.Note:This option is not supported on all platforms at present. It is available if the output of the–helpoption includes this option. See, also, the–excludeto limit recursion.–regex-LANG=/regexp/replacement/[kind-spec/][flags]The/regexp/replacement/pair define a regular expression replacement pattern, similar in style tosedsubstitution commands, with which to generate tags from source files mapped to the named language,LANG, (case-insensitive; either a built-in or user-defined language). The regular expression,regexp, defines an extended regular expression (roughly that used byegrep(1)), which is used to locate a single source line containing a tag and may specify tab characters using \t. When a matching line is found, a tag will be generated for the name defined byreplacement, which generally will contain the special back-references \1 through \9 to refer to matching sub-expression groups withinregexp. The / separator characters shown in the parameter to the option can actually be replaced by any character. Note that whichever separator character is used will have to be escaped with a backslash (\) character wherever it is used in the parameter as something other than a separator. The regular expression defined by this option is added to the current list of regular expressions for the specified language unless the parameter is omitted, in which case the current list is cleared.

Unless modified byflags,regexpis interpreted as a Posix extended regular expression. Thereplacementshould expand for all matching lines to a non-empty string of characters, or a warning message will be reported. An optional kind specifier for tags matchingregexpmay followreplacement, which will determine what kind of tag is reported in the kind extension field (seeTAG FILE FORMAT, below). The full form ofkind-specis in the form of a single letter, a comma, a name (without spaces), a comma, a description, followed by a separator, which specify the short and long forms of the kind value and its textual description (displayed using–list-kinds). Either the kind name and/or the description may be omitted. Ifkind-specis omitted, it defaults tor,regex. Finally,flagsare