CTAGS(1)
π CTAGS(1) β Exuberant Ctags π
okay bestie, sit down, hydrate, and let me tell you about ctags β the Exuberant Ctags manual page, part one of six. It's giving β¨ index generator β¨ and honestly? 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 β we're gonna call them both ctags from here on out unless we specifically gotta tell them apart, k? β they generate an index file (a "tag" file, bestie, keep up π
) for a whole bunch of language objects found in the file(s) you throw at them. And that tag file? It lets a text editor or whatever other utility you've got just... find these items. Fast. Easily. No cap.
A "tag" means a language object that has an index entry available for it β or, alternately, the index entry that got created for that object. Either one, we're calling it a tag. π
Alternatively, ctags can generate a cross reference file, which lists β in a human readable form, we love readability β info about all the various source objects found in a set of language files.
Tag index files are supported by a ton of editors, and they let the user locate the object associated with a name showing up in a source file, then jump straight to the file and line that defines that name. 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 β like, it's versatile, it's multifaceted, it has range π. For a 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.
π SOURCE FILES π
Unless you've specified the --language-force option, the language of each source file gets automatically selected based on a mapping of file names to languages. The mappings in effect for each language can be displayed with the --list-maps option, and can be changed 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 if it's a "#!" script for a recognized language. π§
By default, all other file names are just... ignored. Ignored! π And that's actually a feature, because it means you can run ctags on every file in a single directory (like "ctags *") or on every file in a whole entire source directory tree (like "ctags -R"), and only the files whose names are mapped to languages will get scanned. Slay.
[The reason that .h extensions are mapped to C++ files rather than C files is because it's super common to use .h extensions in C++, and there's no harm in treating them as C++ files.]
π OPTIONS π
Okay so despite the absolute wealth of options available here, the defaults are set up so that ctags is most commonly executed with no options at all (like "ctags *", or "ctags -R"), which creates a tag file in the current directory for all recognized source files. The options below? They exist purely so you can custom-tailor things to meet your special little needs. π«Ά
Note that spaces separating the single-letter options from their parameters are optional. Yes really.
Note also that the boolean parameters to the long form options β the ones beginning with"--"that take a"[=yes|no]"parameter β may be omitted, in which case"=yes"is implied. (e.g.--sortis equivalent to--sort=yes.) And further:"=1"and"=on"are considered synonyms for"=yes", and"=0"and"=off"are considered synonyms for"=no". Vocabulary lesson over, go forth.
Some options are either ignored or only useful when you're running in etags mode (see the -e option). We'll flag those when they come up. π
Most options may appear anywhere on the command line, and they only affect those files which follow the option. A few options, though, must appear before the first file name β and we will absolutely be noting which ones those are.
Options that take language names will accept those names in either upper or lower case. See the --list-languages option for the complete list of built-in language names.
-aβ Equivalent to--append. Simple as that, bestie.-Bβ Use backward searching patterns (e.g.?pattern?). [Ignored in etags mode]-eβ 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 by creating a link to, the executable β then etags mode will be enabled. β οΈ 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.
Ctags will stubbornly refuse to take orders if tagfile exists and its first line contains something other than a valid tags line. Bestie, this will literally 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 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 will apply.
-Fβ Use forward searching patterns (e.g./pattern/) (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 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 located in a non-include file that 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 get appended to the current list; otherwise, the list replaces the current list. See, also, the --file-scope option. 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 supplied to this option is not already mapped to a particular language (see SOURCE FILES, above), you will also need to use either the--langmapor--language-forceoption. Don't forget, or you'll be sad. π₯²
-Iidentifier-list β Specifies 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, ctags will 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 of identifier-list is '@', '.' or a pathname separator ('/' or 'Β΄'), or the first two characters specify a drive letter (e.g. "C:"), the parameter identifier-list will be 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 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 -I options 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 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 (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 to be 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: 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 -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 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: file is 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=number.-Nβ Equivalent to--excmd=pattern.-otagfile β bestie this is literally just-ftagfile, same thing, no notes π-Rβ the short lil twin of--recurse, that's it β¨-uβ equivalent to--sort=no(aka "unsorted", we're going feral, no alphabetizing today) π¦-Vβ equivalent to--verbose. She's chatty, let her talk π-wβ this one is silently ignored for backward-compatibility with thectagsof SVR4 Unix. Not me showing up to the function just to stand there π-xβ prints a tabular, human-readable cross reference (xref) file to standard output instead of generating a tag file. What's in it? 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, periodt. 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[=yes|no]β says whether tags generated from the specified files should be appended to the ones already chilling in the tag file, or straight up replace them. This option is off by default. And yeah, it must appear before the first file name πΈ--etags-include=file β include a reference to file in the tag file. You can say this as many times as you want, go off π It supports Emacs' capability to use a tag file which "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 your heart desires. For every file namectagsconsiders, each pattern you gave gets compared against both the complete path (e.g.some/path/base.ext) and the base name (e.g.base.ext) of the file β so you can match a given file name no matter its path, or only match a specific path, your call β¨
If appropriate support is available from the runtime library of your C compiler, then pattern may contain the usual shell wildcards (not regular expressions!) common on Unix. Be sure to quote the option parameter so the shell doesn't expand those wildcards before they even reach ctags β and also be aware that wildcards can match the slash character, '/'. You can figure out if shell wildcards are available on your platform by peeking at the output of the --version option, which will include "+wildcards" in the compiled feature list; otherwise, pattern is matched against file names using a simple textual comparison.
If pattern begins with the character '@', then the rest of the string is interpreted as a file name from which to read exclusion patterns, one per line. If pattern is empty, the list of excluded patterns is cleared. π§Ή
Heads up: at program startup, the default exclude list contains"EIFGEN","SCCS","RCS", and"CVS"β those are names of directories you generally do not wanna descend into while processing the--recurseoption. It's giving "please don't touch the version control folder" π
--excmd=type β determines the type of EX command used to locate tags in the source file. [Ignored in etags mode] π
The valid values for type (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 as
vim, are able to recover in many such instances). - Eliminates finding identical matching, but incorrect, source lines (see BUGS, below).
- Retains separate entries in the tag file for lines which are identical in content. In pattern mode, 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. Slay, adaptive queen π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 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=[+|-]flags β specifies whether to include extra tag entries for certain kinds of information. The parameter flags is a set of one-letter flags, each representing one kind of extra tag entry to include in the tag file. If flags is preceded 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.qβ 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"class.member". 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=[+|-]flags β specifies the available extension fields which are to be included in the entries of the tag file (see TAG FILE FORMAT, below, for more info). The parameter flags is a set of one-letter flags, each representing one type of extension field to include, with these meanings (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 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 in flags will be included in the output (i.e. overriding the default set, we're going rogue π). This option is ignored if the option --format=1 has been specified. The default value of this option is fkst.
--file-scope[=yes|no]β 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[=yes|no]β 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=string β specifies 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 ofctagsto 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=level β changes the format of the output tag file. Currently the only valid values for level are1or2. Level1specifies the original tag file format and level2specifies a new extended format containing extension fields (but in a manner which retains backward-compatibility with originalvi(1)implementations). The default level is2. This option must appear before the first file name. [Ignored in etags mode] π
--helpβ okay bestie, this one just prints a detailed usage description to standard output and then exits. That's the whole vibe. β¨--if0[=yes|no]β sets a preference about whether code inside an"#if 0"branch of a preprocessor conditional should be checked for non-macro tags (macro tags are always included, periodt). Since the intent of that construct is to disable code, the default value isno. But important: this is only a preference, and it does not guarantee skipping code inside an"#if 0"branch, 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 (or kinds) to include in the output file for a particular language. Here<LANG>is case-insensitive and is one of the built-in language names (see the--list-languagesoption for the 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 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. 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).
Example for C language: 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 is: 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. πΈ--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 to ctags). 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.
- To specify that only files with extensions of
.cand.xare to be treated as C language files, use"--langmap=c:.c.x". - To also add files with extensions of
.jas 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 a particular language, supply the keyword
"default"for the mapping. - To 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, ctags automatically 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). β¨--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. So 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. π--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 causes ctags to generate tag entries marked with the file names and line numbers of their locations in the 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 to ctags. π«Ά--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 into ctags (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 by ctags, and then exits. These language names are case insensitive and may be used in the--language-force,--languages,--<LANG>-kinds, and--regex-<LANG>options. β¨--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). π--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]β bestie this is THE glamour option π it's how you teach ctags your own little pattern-matching rituals. The/regexp/replacement/pair is a regular expression replacement pattern, styled kinda likesedsubstitution commands, and it makes tags out of source files that are mapped to the language named by<LANG>(case-insensitive, and it can be either a built-in language or one you defined yourself, no gatekeeping here).
So regexp is your extended regular expression (roughly the flavor egrep(1) uses), it hunts down a single source line that contains a tag, and yes you can spell tab characters as \t. When a matching line gets caught, a tag is generated for the name defined by replacement, which generally holds the special back-references \1 through \9 pointing at the matching sub-expression groups inside regexp. The / separator characters in the option parameter are honestly just a suggestion β you can swap them for any character you want. Just know that whichever separator character you pick has to be escaped with a backslash character anywhere it shows up in the parameter as something other than a separator. The regex defined by this option gets added to the current list of regexes for that language β unless you omit the parameter entirely, in which case the whole current list gets cleared. π
Unless flags say otherwise, regexp is read as a Posix extended regular expression. And the replacement needs to expand to a non-empty string of characters for every matching line, or you get a warning message, no cap. After replacement you may optionally drop a kind specifier for the tags matching regexp, and that 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), a comma, a description, and then a separator β which together give the short and long forms of the kind value plus its textual description (that's the one shown by --list-kinds). Either the kind name and/or the description can be left out. If kind-spec is omitted entirely it defaults to "r,regex". And finally, flags are one or more single-letter characters that mess with 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: this option only exists if ctags was compiled with support for regular expressions, which totally depends on your platform. You can check if regex support made it in by reading the output of--versionβ it'll include"+regex"in the compiled feature list. β¨
For more info on the regular expressions ctags uses, go read either the regex(5,7) man page or the GNU info documentation for regex (like, "info regex").
--sort[=yes|no|foldcase]β tells ctags whether the tag file should be sorted on the tag name (default isyes, obviously, we love an organized queen). Fun fact: the originalvi(1)required sorted tags, so this is deeply historical behavior. Thefoldcasevalue gives you case-insensitive (aka case-folded) sorting. But listen β fast binary searches of tag files sorted with case-folding need special support from whatever tool is reading the tag files, 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, instead of relative to the current directory β unless the files you handed over on the command line were specified with absolute paths. This option must appear before the first file name. Default isyeswhen you're running in etags mode (see the-eoption), andnootherwise.--totals[=yes|no]β prints statistics about the source files it read and the tag file it wrote during this particular invocation of ctags. This one is off by default. It must appear before the first file name.--verbose[=yes|no]β turns on verbose mode, which prints info on option processing plus a lil brief message describing what action is being taken for each file ctags looks at. Normally ctags doesn't even read the command line arguments until after options are read from the configuration files (see FILES below) and theCTAGSenvironment variable. BUT π if this option is the very 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 and then exits. Guaranteed to always contain the string"Exuberant Ctags". It's giving credentials, it's giving receipts. π
βοΈ 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 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 that's supported on the platform).
If a language got identified, the file is opened and then the appropriate language parser is called to operate on the currently open file. That parser parses through the file and adds an entry to the tag file for every language object it was written to handle. See TAG FILE FORMAT below for the details on those entries. π¦
This implementation of ctags imposes no formatting requirements on C code, unlike those legacy implementations from the olden days. Older implementations of ctags tended to lean on certain formatting assumptions to help them resolve coding dilemmas caused by preprocessor conditionals. Not us. We're modern.
In general, ctags tries to be smart about conditional preprocessor directives. If a preprocessor conditional shows up inside 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 instead. Why? Because not committing to one branch can result in ambiguous syntax, like in this little situation:
#ifdef TWO_ALTERNATIVES
struct {
#else
union {
#endif
short a;
long b;
}
Both branches cannot be followed, or the braces become unbalanced and ctags would be sitting there like π unable to make sense of the syntax.
If applying this heuristic fails to properly parse a file β usually because of complicated and inconsistent pairing inside the conditionals β ctags will retry the file using a different heuristic. That one doesn't selectively follow conditional preprocessor branches at all. Instead it falls back to relying on a closing brace ("}") sitting in column 1 as the indicator that a block ended, once any brace imbalance results from following a #if conditional branch.
Ctags will also try to specially handle argument lists wrapped 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 "((" gets automatically ignored, and the previous name is used instead. Sneaky but correct. π
C++ operator definitions are specially handled. 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 " β yep, even if the actual operator definition was written as "operator<<".
After creating or appending to the tag file, it is sorted by the tag name, and identical tag lines are removed. Cleanup era. β¨
π TAG FILE FORMAT π
Okay bestie, so when you're not in etags mode, every single entry in the tag file is its own little line, and in the most general case it looks like this:
tag_name<TAB>file_name<TAB>ex_cmd;"<TAB>extension_fields
And here's the breakdown of all those fields and separators, one by one:
- the tag name
- a single tab character
- the name of the file where the thing this tag points at actually lives
- a single tab character
- the EX command that finds the tag inside that file β usually a search pattern (either
/pattern/or?pattern?) or a line number (peep--excmdfor that). Now, tag file format 2 (that's--format) extends this EX command, in certain situations, to also carry a set of extension fields (we're getting to those, don't worry) embedded in an EX comment that's glued right onto the end of the EX command β and the way it's done keeps it backward-compatible with the originalvi(1)implementations. cute, right?
A couple of special tags get written into the tag file for internal reasons. These tags are built so they always sort to the very top of the file. So the first two characters of those tags act as a magic number β ctags uses them to detect a tag file, so it can tell whether it's about to overwrite a valid tag file versus an actual source file. π
Also, heads up: the name of each source file gets recorded in the tag file exactly as it appeared on the command line. So if the path you gave was relative to the current directory, that's exactly how it'll be written down in the tag file. If you want to change that behaviour, go look at the --tag-relative option. π
Extension fields are tab-separated key-value pairs tacked onto the end of the EX command as a comment, like we said. They show up in the general form "key:value". Whether they appear in the tag file's lines is controlled by the --fields option. The possible keys and what their values mean:
accessβ shows the visibility of this class member, where the value is specific to the language.fileβ says this tag has file-limited visibility. This key has no corresponding value, bestie. it just is.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 honestly it's the default) for the key portion of this field to be omitted. Those optional behaviors are controlled with the--fieldsoption.implementationβ when it's there, this shows a limited implementation (abstract vs. concrete) of a routine or class, where the value is language-specific ("virtual"or"pure virtual"for C++;"abstract"for Java).inheritsβ when it's there, value. is a comma-separated list of classes this class is derived from (i.e. inherits from).signatureβ when it's there, value is a language-dependent representation of the signature of a routine. A routine signature in its complete form specifies the return type of the 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 all 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 being the name declared for that construct in the program. This scope entry tells you the scope where 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 is gonna expect a tag file named "tags" in the current directory by default. Once the tag file is built, these commands are your tag-indexing besties:
vi -t tagβ starts vi and drops the cursor at the file and line where"tag"is defined.:ta tagβ finds a tag.Ctrl-]β finds the tag under the cursor.Ctrl-Tβ goes back to your previous location, before you jumped to the tag (this one is not widely implemented, ngl).
πΈ HOW TO USE WITH GNU EMACS πΈ
Emacs expects a tag file named "TAGS" in the current directory by default. Once the tag file is built, these commands are how you flex that tag indexing:
M-x visit-tags-table <RET> FILE <RET>β selects the tag file,"FILE", to use.M-. [TAG] <RET>β finds the first definition of TAG. The default tag is the identifier under the cursor.M-*β pops back to where you previously invoked"M-.".C-u M-.β finds the next definition for the last tag.
For even more commands, go read 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, the press Ctrl-D. NEdit 5.1 can 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 π
Because ctags is neither a preprocessor nor a compiler, 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, fr fr. In particular, preprocessor constructs that alter the textual syntax of C can fool ctags. You can work around a lot of these problems with the -I option.
Also β and this is important β since ctags generates patterns for locating tags (see the --excmd option), it is entirely possible that your editor finds the wrong line if there's another source line that's identical to the line containing the tag. Check out this example:
int variable;
/* ... */
void foo(variable)
int variable;
{
/* ... */
}
Depending on which editor you use and where in the code you happen to be, the search pattern might locate the local parameter declaration in foo() before it finds the actual global variable definition, because the lines (and therefore their search patterns) are identical. You can dodge this whole mess by using the --excmd=n option. π
π BUGS π
Ctags has more options than ls(1). iconic behaviour honestly.
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 are read when ctags starts, after the configuration files listed in FILES, below, are read, but before any command line options are read. Options 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 counts as 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, bestie.ETAGSβ similar to the CTAGS variable above; this variable, if found, is read when etags starts. If this variable is not found, etags will 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. ctags creates 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 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 if ctags is setuid, the value ofTMPDIRwill be ignored. π
π¦ FILES π¦
/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 are read in the order listed when ctags starts, but before the CTAGS environment variable is read or any command line options are read. This is what 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). Therefore, use new lines to indicate separate command-line arguments.
tagsβ the default tag file created by ctags.TAGSβ the default tag file created by etags.
π 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 π
Okay bestie, before you close this page, the manpage gets spiritual on you and honestly? Iconic behavior. Here's the energy it wants you to carry:
"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."
-- From the Baha'i Writings
No cap. Write your tags with love. π
π CREDITS π
Giving credit where it's due, because we are not the kind of girl who steals someone's work and pretends she didn't:
- 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 this part is wild, virtually none of the original code remains. Glow-up of the century fr fr. β¨ - 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. π Actual main character energy. π«Ά - The section entitled "HOW TO USE WITH GNU EMACS" was shamelessly stolen from the info page for GNU etags. Not me exposing my own sources in the manpage π at least she's honest.
And that's the whole page, bestie!! You made it to the end of a genuinely enormous manpage and I'm so proud of you. π¦
This one came to you courtesy of Darren Hiebert and Version 5.8 of the manpage for CTAGS(1) β the footer carries the author, the version and the date stamp, so if you ever need to cite exactly which snapshot of this page you read, that bottom line is your receipts. π§Ύβ¨
Now go tag some files. Slay. π πΈ
π¦ where this page comes from
- debian bookworm: arduino-ctags 5.8-arduino11-2 Β· GPL-2.0-only
- debian trixie: arduino-ctags 5.8-arduino11-3 Β· GPL-2.0-only
- ubuntu jammy: arduino-ctags 5.8-arduino11-1 Β· GPL-2.0-only
- ubuntu noble: arduino-ctags 5.8-arduino11-2 Β· GPL-2.0-only
- ubuntu questing: arduino-ctags 5.8-arduino11-3
- ubuntu resolute: arduino-ctags 5.8-arduino11-3build1 Β· GPL-2.0-only
- ubuntu stonking: arduino-ctags 5.8-arduino11-5 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms