CTAGS(1)
CTAGS(1) ๐ the Exuberant Ctags glow-up
okay bestie, sit down, hydrate, because we're about to make tag files and it's gonna be iconic. โจ
โจ NAME โจ
ctags โ generate tag files for source code ๐ท๏ธ
๐ธ SYNOPSIS ๐ธ
ctags [options] [file(s)]
etags [options] [file(s)]
๐ DESCRIPTION ๐
so the ctags and etags programs โ and yes, we're gonna call them both ctags from here on out unless we specifically need to tell them apart, that's just the vibe โ they generate an index (aka a "tag") file for a whole bunch of language objects found in your file(s). and what does that tag file do? it lets a text editor or literally any other utility find those items quickly and easily. a "tag" means a language object that has an index entry available for it โ or, alternatively, it's the index entry itself that got created for that object. both. it's giving dual meaning. ๐ฆ
alternatively, ctags can generate a cross reference file, which lists โ in a form that actual humans can read โ info about all the various source objects hanging out in a set of language files. ๐
tag index files are supported by so many editors, and they let you find the object tied to a name in a source file and jump straight to the file and line that defines it. the ones we knew 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,Zeus
ctags is capable of generating different kinds of tags for each of many different languages. for the complete list of supported languages, the names they're recognized by, and the kinds of tags generated for each โ go check the --list-languages and --list-kinds options. iykyk. ๐
๐ SOURCE FILES ๐
unless you specify the --language-force option, the language of each source file gets auto-selected based on a mapping of file names to languages. the mappings currently in effect for each language can be displayed with the --list-maps option, and you can change them with the --langmap option. on platforms that support it, if a file's name isn't mapped to a language and the file is executable, the first line of the file gets checked to see whether it's a #! script for a recognized language. ๐ง
by default, all other file names are just ignored. and that's actually a feature, not a bug โ it means you can run ctags on every file in a single directory (like ctags *) or on every file in an entire source directory tree (like ctags -R), because only the files whose names are mapped to languages will ever get scanned. slay. ๐ฅ
[the reason.hextensions are mapped to C++ files rather than C files is because it's super common to use.hextensions in C++, and no harm comes from treating them as C++ files.]
โจ OPTIONS โจ
okay so despite the absolute wealth of options available, the defaults are set up so that ctags is most commonly run with zero options at all (like ctags *, or ctags -R), which creates a tag file in the current directory for all recognized source files. all the options below? they exist purely so you can custom-tailor things to meet special needs. ๐
note that spaces separating the single-letter options from their parameters are optional.
also note: the boolean parameters to the long-form options (the ones starting with -- that take a [=yes|no] parameter) may be omitted, and in that case =yes is implied. (e.g. --sort is equivalent to --sort=yes.) and further note that =1 and =on count as synonyms for =yes, while =0 and =off count as synonyms for =no. ๐
some options are either ignored, or only useful, when you're running in etags mode (see the -e option). those options get noted as such. ๐
most options can appear anywhere on the command line, and they only affect the files that come after them. a few options, though, have to appear before the first file name, and those get noted as such. โญ
options that take language names will accept those names in either upper or lower case. check the --list-languages option for a complete list of the built-in language names. ๐ฆ
-aโ equivalent to--append. ๐-Bโ use backward searching patterns (e.g.?pattern?). [ignored in etags mode] โช-eโ enable etags mode, which creates a tag file for use with the Emacs editor. alternatively, ifctagsgets invoked by a name containing the string"etags"(whether by renaming the executable or creating a link to it), etags mode gets enabled automatically. this option must appear before the first file name. โ ๏ธ-ftagfile โ use the name specified by tagfile for the tag file (default is"tags", or"TAGS"when running in etags mode). if tagfile is specified as"-", then the tag file gets written to standard output instead.ctagswill stubbornly refuse to take orders if tagfile already exists and its first line contains something other than a valid tags line. this will save your neck if you mistakenly typectags -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 that begins with a'-'(dash) character, since that most likely means 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 one applies. ๐ซ-Fโ use forward searching patterns (e.g./pattern/) (this is the default). [ignored in etags mode] โฉ-hlist โ specifies 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 kind of tag is interpreted (i.e. whether or not those tags are considered globally visible, or visible only within the file where they're defined); it does not map the extension to any particular language. any tag located in a non-include file that can't 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 get appended to the current list; otherwise, the list replaces the current list. see, also, the--file-scopeoption. the default list is".h.H.hh.hpp.hxx.h++.inc.def". to restore the default list, specify-h default. note that if an extension you supply to this option isn't already mapped to a particular language (see SOURCE FILES, above), you'll also need to use either the--langmapor--language-forceoption. ๐-Iidentifier-list โ specifies a list of identifiers to be specially handled while parsing C and C++ source files. this option exists specifically to handle special cases that come up through the use of preprocessor macros. when the identifiers listed are simple identifiers, those identifiers get ignored during parsing of the source files. if an identifier is suffixed with a'+'character,ctagswill also ignore any parenthesis-enclosed argument list that may immediately follow the identifier in the source files. if two identifiers are separated with the'='character, the first identifier is replaced by the second identifier 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 of identifier-list is'@','.'or a pathname separator ('/'or'\'), or if the first two characters specify a drive letter (e.g."C:"), the parameter identifier-list gets interpreted as a filename from which to read a list of identifiers, one per input line. otherwise, identifier-list is a list of identifiers (or identifier pairs) to be specially handled, each delimited by either a comma or by white space (in which case the list should be quoted to keep the whole list as one command line argument). multiple-Ioptions may be supplied. to clear the list of ignore identifiers, supply a single dash ("-") for identifier-list. ๐ง
this feature is useful when preprocessor macros are used in such a way that they cause syntactic confusion just by existing. in fact, this is the best way to work around a bunch of problems caused by syntax-busting macros in source files (see CAVEATS, 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 as the name of the function instead of the correct name of "foo". specifying -I ARGDECL4 results in the correct behavior. โ
/* creates an RCS version string in module */
MODULE_VERSION("$Revision: 750 $")
in the above example the macro invocation looks way too much like a function definition, because it isn't followed by a semicolon (indeed, it could even be followed by a global variable definition that would look a lot like a K&R style function parameter declaration). in fact, this seeming function definition could possibly even cause the rest of the file to get skipped over while trying to complete the definition. specifying -I MODULE_VERSION+ would avoid such a problem. ๐ฎ๐จ
CLASS Example {
// your content here
};
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 -I CLASS=class. ๐ฏ
-Lfile โ read from file a list of file names for which tags should be generated. if file is specified as"-", then file names get 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 one applies. note: file is read in line-oriented mode, where a new line is the only delimiter and non-trailing white space is considered significant, so that file names containing spaces may be supplied (however, trailing white space is stripped from lines); this can affect how options are parsed if they're included in the input. ๐-nโ equivalent to--excmd=number. ๐ข-Nโ equivalent to--excmd=pattern. ๐ค-o tagfileโ bestie this is literally just-f tagfilewearing a tiny little disguise ๐ same energy, same job.-Rโ shorthand for--recurse. yes queen, go deep into those directories โจ-uโ shorthand for--sort=no, aka "unsorted", i.e. it keeps things in the order it found them, no sorting era ๐-Vโ shorthand for--verbose. she's gonna tell you EVERYTHING ๐ฌ-wโ silently ignored, purely for backward-compatibility with the ctags of SVR4 Unix. it's giving "vintage, but make it chill" ๐ it does nothing, no cap.-xโ prints a tabular, human-readable cross reference (xref) file straight to standard output instead of generating a tag file. no tag file gets written, and every option that affects tag file output gets ignored, periodt. what's in the output? the tag name; the kind of tag; the line number, file name, and source line (with extra white space condensed, slay) of the file that defines the tag. use cases she's serving: generating a listing of all functions in a source file (likectags -x --c-kinds=f file), or a list of all externally visible global variables in a source file (likectags -x --c-kinds=v --file-scope=no file). โ ๏ธ this option must appear before the first file name.--append[=yes|no]โ tells you whether tags generated from the specified files get appended to what's already in the tag file, or replace them. it's off by default. and yeah, this option must appear before the first file name ๐ซถ--etags-include=fileโ drops a reference to file into the tag file. you can specify this as many times as you want, go off ๐ it supports Emacs' ability to use a tag file that "includes" other tag files. [Available only in etags mode] ๐--exclude=[pattern]โ adds pattern to a list of excluded files and directories. specify it as many times as you like, no limits bestie. for every file name ctags looks at, each pattern gets compared against both the complete path (e.g.some/path/base.ext) and the base name (e.g.base.ext) โ so you can match a file name no matter its path, or match only one specific path. if your C compiler's runtime library has the right support, pattern can hold the usual shell wildcards (NOT regular expressions, don't get it twisted) common on Unix. ๐ be sure to quote the option parameter so the shell doesn't expand the wildcards before ctags even sees them, and heads up: wildcards can match the slash character/. you can find out if shell wildcards are available on your platform by checking the output of the--versionoption โ it'll include+wildcardsin the compiled feature list. otherwise, pattern gets matched against file names using a simple textual comparison.
if pattern starts with the character @, then the rest of the string is read as a file name to read exclusion patterns from, one per line. and if pattern is empty, the whole list of excluded patterns gets cleared. ๐งน
ngl, at program startup the default exclude list already contains"EIFGEN","SCCS","RCS", and"CVS"โ those are directory names you generally do NOT wanna descend into while processing the--recurseoption. she's protecting you from yourself ๐
--excmd=typeโ picks the type of EX command used to locate tags in the source file. [Ignored in etags mode] โจ
valid values for type (either the whole word or just the first letter works, we're flexible like that):
numberโ use only line numbers in the tag file to locate 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 changed, which makes the pattern match fail (note that some editors, like vim, can recover in many of those instances, iconic)
- eliminates finding identical matching but incorrect source lines (see BUGS, below)
- retains separate entries in the tag file for lines that are identical in content. in pattern mode, duplicate entries get dropped because the search patterns they generate are identical, which makes those duplicates useless anyway.
but bestie there's one significant drawback ๐ญ: changes to the source files can make the line numbers recorded in the tag file stop matching the actual lines, so jumps to some tags can miss the target definition by one or more lines. basically, this option is best used when the source code it's applied to is not subject to change. and choosing this option type makes the following options get ignored: -BF. ๐
patternโ use only search patterns for all tags, instead of the line numbers usually used for macro definitions. the advantage: no referencing obsolete line numbers when lines have been added or removed since the tag file was generated โจmixedโ 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 original ctags, so it's retained as the default for this option ๐ for Fortran, line numbers are used for common blocks, because their corresponding source lines are generally identical, which makes pattern searches useless for finding all matches.
--extra=[+|-]flagsโ decides whether to include extra tag entries for certain kinds of info. flags is a set of one-letter flags, each one representing a kind of extra tag entry to add to the tag file. if flags is preceded by a+or-character, each flag's effect is added to or removed from the ones currently enabled. otherwise the flags replace any current settings. here's what each flag means: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 ๐qโ include an extra class-qualified tag entry for each tag that's a member of a class (for languages where this info gets extracted; currently C++, Eiffel, and Java). the actual form of the qualified tag depends on the language it came from, using whatever form is most natural for how qualified calls are specified in that language. for C++, it's in the form"class::member"; for Eiffel and Java, it's in the form"class.member". this may make it easier to locate a specific tag when multiple occurrences of a tag name show up in the tag file ๐ but note, this could potentially more than double the size of the tag file ๐ญ
--fields=[+|-]flagsโ picks which available extension fields get included in the tag file entries (see TAG FILE FORMAT, below, for more). flags is a set of one-letter flags, each representing one type of extension field to include, and here's what they mean (disabled by default unless indicated):aโ Access (or export) of class membersfโ File-restricted scoping [enabled]iโ Inheritance informationkโ Kind of tag as a single letter [enabled]Kโ Kind of tag as full namelโ Language of source file containing tagmโ Implementation informationnโ Line number of tag definitionsโ Scope of tag definition [enabled]Sโ Signature of routine (e.g. prototype or parameter list)zโ Include the"kind:"key in kind fieldtโ Type and name of a variable or typedef as"typeref:"field [enabled]
each letter or group of letters can be preceded by + to add it to the default set, or - to exclude it. if there's no + or - in front, then only the kinds explicitly listed in flags get included in the output (i.e. it overrides the default set, no cap). ๐ซถ this option gets ignored if the option --format=1 has been specified. the default value of this option is fkst. โญ
--file-scope[=yes|no]โ says whether tags scoped only for a single file (i.e. tags that can't be seen outside the file they're defined in, like"static"tags) should be included in the output. also peep the-hoption for more. this option is enabled by default ๐--filter[=yes|no]โ makes ctags behave as a filter: it reads source file names from standard input and prints their tags to standard output on a file-by-file basis, slay ๐ if--sortedis enabled, tags get sorted only within the source file they're defined in. file names are read from standard input in line-oriented input mode (see the note for the-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--totalsget ignored. this option is quite esoteric and is disabled by default. and yes, this option must appear before the first file name.--filter-terminator=stringโ sets a string to print to standard output after the tags for each file name parsed when--filteris enabled. this may let an application reading ctags' output figure out when the output for each file is finished ๐ note that if the file name read is a directory and--recurseis enabled, this string gets printed only once, at the end of all tags found from descending the directory. this string is always separated from the last tag line for the file by its terminating newline. this option is quite esoteric and is empty by default. and yeah, this option must appear before the first file name.--format=levelโ changes the format of the output tag file. currently the only valid values for level are1or2. level1is the original tag file format, and level2is a new extended format containing extension fields (but in a way that stays backward-compatible with originalvi(1)implementations, iconic ๐). the default level is2. this option must appear before the first file name. [Ignored in etags mode] โจ--helpโ prints a whole detailed usage description to standard output and then dips out (exits). bye bestie ๐--if0[=yes|no]โ ok so this one is a vibe preference, not a promise. It says whether code sitting inside an#if 0branch of a preprocessor conditional should even be looked at for non-macro tags (macro tags are always included, no matter what). Because the whole point of that construct is "turn this code off," the default value isno. But heads up: this is a preference only and it does not guarantee that code inside an#if 0branch gets skipped, because 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=[+|-]kindsโ specifies a list of language-specific kinds of tags (aka kinds) to include in the output file for a particular language, where<LANG>is case-insensitive and is one of the built-in language names (peep--list-languagesfor the full list โจ). The parameterkindsis a lil 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 listed 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. And if there's no preceding+or-sign at all? Then only those kinds explicitly listed inkindswill be included in the output (i.e. overriding the default for the specified language). so real
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=nameโ defines 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-<LANG>to define how its tags are found. build your own language era ๐ฆ--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=languageโ by default,ctagsautomatically selects the language of a source file, ignoring those files whose language cannot be determined (see SOURCE FILES, above). This option forces the specified language (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). forcing the issue fr--languages=[+|-]listโ specifies 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. โจ--licenseโ prints a summary of the software license to standard output, and then exits. the receipts, bestie ๐--line-directives[=yes|no]โ 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 source file(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 source file(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#linedirective 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[=yes|no]โ indicates whether symbolic links (if supported) should be followed. When disabled, symbolic links are ignored. This option is on by default.--list-kinds[=language|all]โ 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-<LANG>option). Each kind listed is enabled unless followed by"[off]". ๐--list-maps[=language|all]โ 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, and SOURCE FILES, above.--list-languagesโ lists 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-<LANG>options. the full roster ๐--options=fileโ read 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 (see FILES). no cap, order matters here--recurse[=yes|no]โ 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 don't 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]โ okay so this is the glow-up option, bestie. It's how you teach ctags a whole new trick. The/regexp/replacement/pair is a regular expression replacement pattern, same energy as asedsubstitution command, and it generates tags from source files mapped to the language<LANG>(case-<em>insensitive</em>, and it can be a built-in language or one you made yourself, no cap). Theregexpis an extended regular expression (roughly the kindegrep(1)uses), and it's used to find a single source line containing a tag โ and yes you can spell tab characters with\t. ๐ซถ
When a matching line gets found, a tag is generated for the name defined by replacement, which generally contains the special back-references \1 through \9 to point at matching sub-expression groups inside regexp. And here's the cute part: those / separator characters you see in the option's parameter can actually be replaced by any character. โ ๏ธ But whichever separator character you pick, you'll have to escape it with a backslash (\) anywhere it shows up in the parameter as something other than a separator. The regular expression this option defines gets added to the current list of regular expressions for that language โ unless you omit the parameter entirely, in which case the current list gets cleared. ๐
Unless flags mess with it, regexp is read as a Posix extended regular expression. The replacement should expand to a non-empty string of characters for all matching lines, or you'll get a warning message reported. After replacement you may put an optional kind specifier for the tags matching regexp, which decides what kind of tag gets reported in the "kind" extension field (peep TAG FILE FORMAT, below). The full form of kind-spec is: a single letter, a comma, a name (no spaces allowed, tyvm), a comma, a description, followed by a separator โ and those specify the short and long forms of the kind value plus its textual description (which is what --list-kinds shows you). Either the kind name and/or the description may be omitted. If kind-spec is omitted altogether, it defaults to "r,regex". โจ
Finally, flags is one or more single-letter characters, and here's what each one does to how regexp is interpreted:
bโ the pattern is interpreted as a Posix basic regular expression.eโ the pattern is interpreted as a Posix extended regular expression (this is the default).iโ the regular expression is applied in a case-insensitive manner.
Heads up, bestie: this option is available only if ctags was compiled with support for regular expressions, which depends on your platform. ๐ You can figure out if regex support is compiled in by looking at the output of the--versionoption โ it'll include"+regex"in the compiled feature list.
For more info on the regular expressions ctags uses, see either the regex(5,7) man page, or the GNU info documentation for regex (e.g. "info regex"). ๐
--sort[=yes|no|foldcase]โ tells ctags whether the tag file should be sorted on the tag name (default isyes). Fun history moment: the originalvi(1)required sorted tags. ๐ Thefoldcasevalue means case-insensitive (or case-folded) sorting. And listen โ fast binary searches of tag files sorted with case-folding will need special support from whatever tool is reading the tag file, like the support found in the ctagsreadtagslibrary, or Vim version 6.2 or higher (using"set ignorecase"). This option must appear before the first file name. [Ignored in etags mode] ๐--tag-relative[=yes|no]โ says the file paths recorded in the tag file should be relative to the directory containing the tag file, rather than relative to the current directory โ unless the files you hand over on the command line are given with absolute paths. This option must appear before the first file name. The default isyeswhen running in etags mode (see the-eoption), andnootherwise. ๐--totals[=yes|no]โ prints statistics about the source files read and the tag file written during this invocation of ctags. Off by default. This option must appear before the first file name. ๐--verbose[=yes|no]โ enables verbose mode, which prints out info on option processing plus a brief message describing what action is being taken for each file ctags considers. Normally ctags doesn't read command line arguments until after options are read from the configuration files (see FILES, below) and theCTAGSenvironment variable. But โ plot twist โ if this option is the first argument on the command line, it takes effect before any options are read from those sources. Default isno. ๐ฆ--versionโ prints a version identifier for ctags to standard output, then exits. And this is guaranteed to always contain the string"Exuberant Ctags". โญ
๐ OPERATIONAL DETAILS ๐
As ctags considers each file name in turn, it tries to figure out the language of the file by running these three tests, in this order: whether the file extension has been mapped to a language, whether the file name matches a shell pattern mapped to a language, and finally whether the file is executable and its first line specifies an interpreter using the Unix-style "#!" specification (if your platform supports that). If a language got identified, the file is opened and then the appropriate language parser is called to operate on the currently open file. The parser parses through the file and adds an entry to the tag file for each language object it's written to handle. See TAG FILE FORMAT, below, for the deets on those entries. ๐
This implementation of ctags imposes no formatting requirements on C code, unlike legacy implementations. Older implementations of ctags tended to rely on certain formatting assumptions to help them resolve coding dilemmas caused by preprocessor conditionals. Not us. โจ
In general, ctags tries to be smart about conditional preprocessor directives. If a preprocessor conditional is encountered within a statement that defines a tag, ctags follows only the first branch of that conditional โ except in the special case of "#if 0", where it follows only the last branch. Why? Because failing to pursue only one branch can result in ambiguous syntax, like in this example:
#ifdef TWO_ALTERNATIVES
struct {
#else
union {
#endif
short a;
long b;
}
Both branches cannot be followed, or braces become unbalanced and ctags would be unable to make sense of the syntax. ๐
If applying that heuristic fails to properly parse a file โ usually because of complicated and inconsistent pairing within the conditionals โ ctags will retry the file using a different heuristic which does not selectively follow conditional preprocessor branches. Instead it falls back to relying upon a closing brace ("}") in column 1 as indicating the end of a block, once any brace imbalance results from following a #if conditional branch. ๐ซ
Ctags will also try to specially handle argument lists enclosed in double sets of parentheses, so it can accept this conditional construct:
extern void foo __ARGS((int one, char two));
Any name immediately preceding the "((" will be automatically ignored, and the previous name will be used instead. ๐
C++ operator definitions get special handling too. For consistency across all types of operators (overloaded and conversion), the operator name in the tag file will always be preceded by the string "operator " โ i.e. even if the actual operator definition was written as "operator<<". ๐
After creating or appending to the tag file, it gets sorted by the tag name, and identical tag lines are removed. ๐งน
๐ TAG FILE FORMAT ๐
okay bestie so when you're not running in etags mode, every single entry in the tag file is its own line, and in the most general case it looks exactly like this:
tag_name<TAB>file_name<TAB>ex_cmd;"<TAB>extension_fields
and the fields + separators break down like this, in order:
- the tag name ๐ท๏ธ
- one single tab character
- the name of the file where the object associated with the tag actually lives
- one single tab character
- the EX command used to locate the tag inside the file โ generally a search pattern (either
/pattern/or?pattern/) or a line number (peep--excmdfor that). Tag file format 2 (see--format) extends this EX command under certain circumstances to include a set of extension fields (described below) embedded in an EX comment immediately appended to the EX command, which keeps it backward-compatible with the originalvi(1)implementations. iconic behaviour honestly ๐
A few special tags get written into the tag file for internal purposes. These tags are composed in such a way that they always sort to the top of the file. So the first two characters of these tags are used as a magic number to detect a tag file โ which is how it figures out whether it's about to overwrite a valid tag file versus an actual source file. lowkey genius ngl
note that the name of each source file gets recorded in the tag file exactly as it appears on the command line. so if the path you gave on the command line was relative to the current directory, it gets recorded that same way in the tag file. see the --tag-relative option for how this behaviour can be modified. ๐ฆ
Extension fields are tab-separated key-value pairs appended to the end of the EX command as a comment, exactly as described above. These key-value pairs show up in the general form "key:value". Whether they appear in the lines of the tag file is controlled by the --fields option. The possible keys and what their values mean are:
accessโ says the visibility of this class member, where the value is specific to the language.fileโ says the tag has file-limited visibility. This key has no corresponding value.kindโ says the type, or kind, of tag. Its value is either one of the corresponding one-letter flags described under the various--<LANG>-kindsoptions above, or a full name. It's permitted (and it's actually the default!) for the key portion of this field to be omitted. The optional behaviours are controlled with the--fieldsoption.implementationโ when present, this says a limited implementation (abstract vs. concrete) of a routine or class, where the value is specific to the language ("virtual"or"pure virtual"for C++;"abstract"for Java).inheritsโ when present, value is a comma-separated list of classes that this class is derived from (i.e. inherits from).signatureโ when present, value is a language-dependent representation of the signature of a routine. A routine signature in its complete form specifies the return type of a routine and its formal argument list. This extension field is presently supported only for C-based languages and does not include the return type.
On top of that, info on the scope of the tag definition may be available, with the key portion equal to some language-dependent construct name and its value the name declared for that construct in the program. This scope entry says the scope in which the tag was found. For example, a tag generated for a C structure member would have a scope looking like "struct:myStruct". ๐ซถ
๐ HOW TO USE WITH VI ๐
Vi will, by default, expect a tag file named "tags" in the current directory. Once the tag file is built, these commands are what exercise the tag indexing feature:
vi -t tagโ starts vi and puts the cursor at the file and line where"tag"is defined.:ta tagโ find a tag.Ctrl-]โ find the tag under the cursor.Ctrl-Tโ return to the previous location before you jumped to the tag (not widely implemented, sadly ๐ญ).
๐ HOW TO USE WITH GNU EMACS ๐
Emacs will, by default, expect a tag file named "TAGS" in the current directory. Once the tag file is built, these commands are what exercise the tag indexing feature:
M-x visit-tags-table <RET> FILE <RET>โ select the tag file,"FILE", to use.M-. [TAG] <RET>โ find the first definition ofTAG. The default tag is the identifier under the cursor.M-*โ pop back to where you previously invokedM-..C-u M-.โ find the next definition for the last tag.
for more commands, go look at the Tags topic in the Emacs info document. โจ
๐ HOW TO USE WITH NEDIT ๐
NEdit version 5.1 and later can handle the new extended tag file format (see --format). To make NEdit use the tag file, select "File->Load Tags File". To jump to the definition for a tag, highlight the word, then press Ctrl-D. NEdit 5.1 can read multiple tag files from different directories. Setting the X resource nedit.tagFile to the name of a tag file tells NEdit to automatically load that tag file at startup time. ๐
๐ญ CAVEATS ๐ญ
okay so because ctags is neither a preprocessor nor a compiler, use of preprocessor macros can fool ctags into either missing tags or improperly generating inappropriate tags. Even though ctags has been designed to handle certain common cases, this is the single biggest cause of reported problems. In particular, the use of preprocessor constructs which alter the textual syntax of C can fool ctags. You can work around many such problems by using the -I option. ๐
Also note: since ctags generates patterns for locating tags (see the --excmd option), it's entirely possible that the wrong line may be found by your editor if there exists another source line which is identical to the line containing the tag. The following example demonstrates this condition:
int variable;
/* ... */
void foo(variable)
int variable;
{
/* ... */
}
Depending on which editor you use and where in the code you happen to be, it's possible that the search pattern may locate the local parameter declaration in foo() before it finds the actual global variable definition, since the lines (and therefore their search patterns) are identical. You can dodge this with the --excmd=n option. ๐ซก
๐ BUGS ๐
Ctags has more options than ls(1). not me saying that fr fr ๐
When parsing a C++ member function definition (e.g. "className::function"), ctags cannot determine whether the scope specifier is a class name or a namespace specifier and always lists it as a class name in the scope portion of the extension fields. Also, if a C++ function is defined outside of the class declaration (the usual case), the access specification (i.e. public, protected, or private) and implementation information (e.g. virtual, pure virtual) contained in the function declaration are not known when the tag is generated for the function definition. It will, however, be available for prototypes (e.g. --c++-kinds=+p).
No qualified tags are generated for language objects inherited into a class. ๐
๐ ENVIRONMENT VARIABLES ๐
CTAGSโ if this environment variable exists, it's expected to contain a set of default options which get read whenctagsstarts, after the configuration files listed in FILES below are read, but before any command line options are read. Options appearing on the command line will override options specified in this variable. Only options will be read from this variable. Note that all white space in this variable is considered a separator, which makes it impossible to pass an option parameter containing an embedded space. If that's a problem, use a configuration file instead. ๐ETAGSโ similar to theCTAGSvariable above; this variable, if found, will be read whenetagsstarts. If this variable is not found,etagswill try to useCTAGSinstead.TMPDIRโ on Unix-like hosts wheremkstemp()is available, the value of this variable specifies the directory in which to place temporary files. This can be useful if the size of a temporary file becomes too large to fit on the partition holding the default temporary directory defined at compilation time.ctagscreates temporary files only if either (1) an emacs-style tag file is being generated, (2) the tag file is being sent to standard output, or (3) the program was compiled to use an internal sort algorithm to sort the tag files instead of the sort utility of the operating system. If the sort utility of the operating system is being used, it will generally observe this variable also. Note that ifctagsis setuid, the value ofTMPDIRwill be ignored. ๐ณ
๐ FILES ๐
- **/ctags.cnf** (on MSDOS, MSWindows only)โ wait no, let me actually list these properly, bestie:/ctags.cnf(on MSDOS, MSWindows only)/etc/ctags.conf/usr/local/etc/ctags.conf$HOME/.ctags$HOME/ctags.cnf(on MSDOS, MSWindows only).ctagsctags.cnf(on MSDOS, MSWindows only)
If any of these configuration files exist, each is expected to contain a set of default options which get read in the order listed when ctags starts, but before the CTAGS environment variable is read or any command line options are read. This makes it possible to set up site-wide, personal, or project-level defaults. It's possible to compile ctags to read an additional configuration file before any of those shown above, which will be indicated if the output produced by the --version option lists the "custom-conf" feature. Options appearing in the CTAGS environment variable or on the command line will override options specified in these files. Only options will be read from these files. Note that the option files are read in line-oriented mode in which spaces are significant (since shell quoting is not possible). Each line of the file is read as one command line parameter (as if it were quoted with single quotes). So use new lines to indicate separate command-line arguments. ๐ง
tagsโ the default tag file created byctags.TAGSโ the default tag file created byetags.
๐ SEE ALSO ๐
The official Exuberant Ctags web site at:
http://ctags.sourceforge.net
Also ex(1), vi(1), elvis, or, better yet, vim, the official editor of ctags. For more information on vim, see the VIM Pages web site at:
http://www.vim.org/
๐ธ AUTHOR ๐ธ
Darren Hiebert <dhiebert at users.sourceforge.net>
http://DarrenHiebert.com/
๐ธ MOTIVATION ๐ธ
ok so before we get into anything else, bestie, let's talk about why. The original author opened this whole page with two quotes and honestly? they ate. ๐
"Think ye at all times of rendering some service to every member of the human race."
"All effort and exertion put forth by man from the fullness of his heart is worship, if it is prompted by the highest motives and the will to do service to humanity."
and that second one is signed:
-- From the Baha'i Writings
like. the way that a tag file generator manpage opens with a whole spiritual mission statement?? iconic. no cap. ๐ซถ
๐ CREDITS ๐
ngl this part is basically the ctags hall of fame and everyone here deserves their flowers. ๐น
- This version of ctags was originally derived from and inspired by the ctags program by Steve Kirkendall
<kirkenda@cs.pdx.edu>that comes with the Elvis vi clone โ though, and I quote, virtually none of the original code remains. (so likeโฆ the vibe was inherited, not the code ๐) - Credit is also due Bram Moolenaar
<Bram@vim.org>, the author of vim, who has devoted so much of his time and energy both to developing the editor as a service to others, and to helping the orphans of Uganda. literally main character energy on every axis. ๐ - The section entitled
"HOW TO USE WITH GNU EMACS"was shamelessly stolen from the info page for GNU etags. (their words!! not mine!! we're just being honest in here ๐)
so yeah, that's the whole page bestie ๐ go make some tags, go jump around your codebase, go be the person who actually knows what -R does. the source/version line at the bottom of this manpage belongs to Darren Hiebert and reads Version 5.9~svn20110310, dated for the CTAGS(1) page โ so shoutout to Darren, and consider this your cute little sign-off. mwah. ๐โจ
๐ฆ where this page comes from
- debian bookworm: exuberant-ctags 1:5.9~svn20110310-18 ยท GPL-2.0-or-later
- debian trixie: exuberant-ctags 1:5.9~svn20110310-19 ยท GPL-2.0-or-later
- ubuntu jammy: exuberant-ctags 1:5.9~svn20110310-16build1 ยท GPL-2.0-or-later
- ubuntu jammy: exuberant-ctags 1:5.9~svn20110310-16ubuntu0.22.04.1 ยท GPL-2.0-or-later
- ubuntu noble: exuberant-ctags 1:5.9~svn20110310-19build1 ยท GPL-2.0-or-later
- ubuntu questing: exuberant-ctags 1:5.9~svn20110310-19build1
- ubuntu resolute: exuberant-ctags 1:5.9~svn20110310-20 ยท GPL-2.0-or-later
- ubuntu stonking: exuberant-ctags 1:5.9~svn20110310-20 ยท GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms