ctags(1)

๐Ÿ“ฆ
version 6.2.1 ยท 3 versions
, in ubuntu resolute, ubuntu stonking

๐ŸŒธ Name ๐ŸŒธ

hey bestie, welcome to the ctags(1) manual โ€” this is Universal Ctags and it's literally here to generate tag files for source code โœจ. That's the whole name section. Periodt. ๐Ÿ’…

โœจ SYNOPSIS โœจ

ctags [<options>] [<source_file(s)>]
etags [<options>] [<source_file(s)>]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so the ctags and etags programs (peep the -e option for etags mode) โ€” and bestie, we're gonna collectively call them ctags from here on, except where we need to distinguish them โ€” they generate an index (or "tag") file for a whole variety of language objects found in source file(s). This tag file is the moment because it lets these items be quickly and easily located by a text editor or other utilities (client tools). A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object). iykyk โœจ

Alternatively, ctags can generate a cross reference file which lists, in human readable form, information about the various language objects found in a set of source files. ๐Ÿ’…

Tag index files are supported by numerous editors, which allow the user to locate the object associated with a name appearing in a source file and jump to the file and line which defines the name. See the manual of your favorite editor about utilizing the ctags command and the tag index files in the editor. ๐ŸŽ€

ctags is capable of generating different kinds of tags for each of many different languages. For a complete list of supported languages, the names by which they are recognized, and the kinds of tags which are generated for each, see the --list-languages and --list-kinds-full options. No cap. ๐Ÿ”ฅ

This man page describes Universal Ctags, an implementation of ctags derived from Exuberant Ctags. The major incompatible changes between Universal Ctags and Exuberant Ctags are enumerated in ctags-incompatibilities(7). ๐Ÿซถ

One of the advantages of Exuberant Ctags is that it allows a user to define a new parser from the command line. Extending this capability is one of the major features of Universal Ctags. ctags-optlib(7) describes how the capability is extended. ๐ŸŒˆ

Newly introduced experimental features are not explained here. If you are interested in such features and ctags internals, visit <https://docs.ctags.io/>. โœจ

๐Ÿ‘‘ COMMAND LINE INTERFACE ๐Ÿ‘‘

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

Note that spaces separating the single-letter options from their parameters are optional. ๐ŸŽ€

Note also that the boolean parameters to the long form options (those beginning with -- and that take a [=(yes|no)] parameter) may be omitted, in which case =yes is implied. (e.g. --sort is equivalent to --sort=yes). Note further that =1, =on, and =true are considered synonyms for =yes, and that =0, =off, and =false are considered synonyms for =no. โœจ

Some options are either ignored or useful only when used while running in etags mode (see -e option). Such options will be noted. ๐Ÿ‘€

<options> must precede the <source_file(s)> following the standard POSIX convention. ๐Ÿ’–

Options taking language names will accept those names in either upper or lower case. See the --list-languages option for a complete list of the built-in language names. ๐ŸŒธ

๐ŸŽ€ Letters and names ๐ŸŽ€

Some options take one-letter flags as parameters (e.g. --kinds-<LANG> option). Specifying just letters helps a user create a complicated command line quickly. However, a command line including sequences of one-letter flags becomes difficult to understand. ๐Ÿ˜ญ

Universal Ctags accepts long-name flags in addition to such one-letter flags. The long-name and one-letter flags can be mixed in an option parameter by surrounding each long-name by braces. Thus, for an example, the following three notations for --kinds-C option have the same meaning:

--kinds-C=+pLl
--kinds-C=+{prototype}{label}{local}
--kinds-C=+{prototype}L{local}

Note that braces may be meta characters in your shell. Put single quotes in such case. ๐Ÿซถ

--list-... options shows one-letter flags and associated long-name flags. ๐Ÿ’…

๐Ÿฆ‹ List options ๐Ÿฆ‹

Universal Ctags introduces many --list-... options that provide the internal data of Universal Ctags (See "Listing Options"). Both users and client tools may use the data. --with-list-header and --machinable options adjust the output of the most of --list-... options. โœจ

The default setting (--with-list-header=yes and --machinable=no) is for using interactively from a terminal. The header that explains the meaning of columns is simply added to the output, and each column is aligned in all lines. The header line starts with a hash ('#') character. ๐Ÿ’–

For scripting in a client tool, --with-list-header=no and --machinable=yes may be useful. The header is not added to the output, and each column is separated by tab characters. ๐ŸŽ€

Note the order of columns will change in the future release. However, labels in the header will not change. So by scanning the header, a client tool can find the index for the target column. ๐ŸŒˆ

๐Ÿ’… OPTIONS ๐Ÿ’…

ctags has more options than listed here. Options starting with an underscore character, such as --_echo=<msg>, are not listed here. They are experimental or for debugging purpose. ๐Ÿ‘€

Notation: <foo> is for a variable string foo, [ ... ] for optional, | for selection, and ( ... ) for grouping. For example --foo[=(yes|no)] means --foo, --foo=yes, or --foo=no. โœจ

๐ŸŒธ Input/Output File Options ๐ŸŒธ

  • --exclude=<pattern> โ€” Add <pattern> to a list of excluded files and directories. This option may be specified as many times as desired. For each file name considered by ctags, each pattern specified using this option will be compared against both the complete path (e.g. some/path/base.ext) and the base name (e.g. base.ext) of the file, thus allowing patterns which match a given file name irrespective of its path, or match only a specific path. ๐Ÿซถ

If appropriate support is available from the runtime library of your C compiler, then pattern may contain the usual shell wildcards (not regular expressions) common on Unix (be sure to quote the option parameter to protect the wildcards from being expanded by the shell before being passed to ctags; also be aware that wildcards can match the slash character, '/'). You can determine if shell wildcards are available on your platform by examining the output of the --list-features 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. โœจ

Note that at program startup, the default exclude list contains names of common hidden and system files, patterns for binary files, and directories for which it is generally not desirable to descend while processing the --recurse option. To see the list of built-in exclude patterns, use --list-excludes. ๐Ÿ‘‘

See also the description for --exclude-exception= option. ๐Ÿ’–

  • --exclude-exception=<pattern> โ€” Add <pattern> to a list of included files and directories. The pattern affects the files and directories that are excluded by the pattern specified with --exclude= option. ๐ŸŽ€

For an example, you want ctags to ignore all files under foo directory except foo/main.c, use the following command line: --exclude=foo/* --exclude-exception=foo/main.c. ๐ŸŒธ

  • --filter[=(yes|no)] โ€” Makes ctags 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 --sort is 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 -L option) and only after file names listed on the command line or from any file supplied using the -L option. When this option is enabled, the options -f, -o, and --totals are ignored. This option is quite esoteric and is disabled by default. ๐Ÿ’…
  • --filter-terminator=<string> โ€” Specifies a <string> to print to standard output following the tags for each file name parsed when the --filter option is enabled. This may permit an application reading the output of ctags to determine when the output for each file is finished. ๐Ÿฆ‹

Note that if the file name read is a directory and --recurse is enabled, this string will be printed only 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. ๐ŸŽ€

  • --links[=(yes|no)] โ€” Indicates whether symbolic links (if supported) should be followed. When disabled, symbolic links are ignored. This option is on by default. ๐Ÿ’–
  • --maxdepth=<N> โ€” Limits the depth of directory recursion enabled with the --recurse (-R) option. ๐ŸŒˆ
  • --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 -L option, then the current directory (i.e. '.') is assumed. Symbolic links are followed by default (See --links option). If you don't like these behaviors, either explicitly specify the files or pipe the output of find(1) into ctags -L - instead. See, also, the --exclude and --maxdepth to limit recursion. ๐Ÿ’…

Note: This option is not supported on all platforms at present. It is available if the output of the --help option includes this option. ๐Ÿ˜ญ

  • -R โ€” Equivalent to --recurse. โœจ
  • -L <file> โ€” 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.
  • --append[=(yes|no)] โ€” says whether tags made from the files you listed get appended to whateverโ€™s already in the tag file, or replace it entirely. Default? no, bestie โ€” so it replaces. ๐Ÿ’…
  • -a โ€” literally the same thing as --append. periodt.
  • -f <tagfile> โ€” use the name in <tagfile> for the tag file (default is tags, or TAGS when running in etags mode). If <tagfile> is specified as -, then the tags get 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. This will save your neck if you mistakenly type ctags -f *.c, which would otherwise overwrite your first C file with the tags generated by the rest! It will also refuse to accept a multi-character file name which begins with a - (dash) character, since this most likely means that you left out the tag file name and this option tried to grab the next option as the file name. If you really want to name your output tag file -ugly, specify it as -f ./-ugly.

This option must appear before the first file name. If this option is specified more than once, only the last will apply. ๐Ÿซถ

  • -o <tagfile> โ€” equivalent to -f tagfile.

โœจ Output Format Options โœจ

  • --format=(1|2) โ€” change the format of the output tag file. Currently the only valid values for level are 1 or 2. Level 1 specifies the original tag file format, and level 2 specifies a new extended format containing extension fields (but in a manner which retains backward-compatibility with original vi(1) implementations). The default level is 2. [Ignored in etags mode] ๐Ÿ‘‘
  • --output-format=(u-ctags|e-ctags|etags|xref|json) โ€” specify the output format. The default is u-ctags. See tags(5) for u-ctags and e-ctags. TAG_OUTPUT_MODE pseudo tag indicates the choice, u-ctags or e-ctags. See ctags-client-tools(7) for more about the pseudo tag. See -e for etags, and -x for xref. json format is available only if the ctags executable is built with libjansson. See ctags-json-output(5) for more about json format. See also --list-output-formats. ๐ŸŒˆ
  • -e โ€” same as --output-format=etags. Enable etags mode, which will create a tag file for use with the Emacs editor. Alternatively, if ctags is invoked by a name containing the string etags (either by renaming, or creating a link to, the executable), etags mode will be enabled. ๐Ÿ’–
  • -x โ€” same as --output-format=xref. Print a tabular, human-readable cross reference (xref) file to standard output instead of generating a tag file. The information contained in the output includes: the tag name; the kind of tag; the line number, file name, and source line (with extra white space condensed) of the file which defines the tag. No tag file is written and all options affecting tag file output will be ignored. Example applications for this feature are generating a listing of all functions located in a source file (e.g. ctags -x --kinds-c=f file), or generating a list of all externally visible global variables located in a source file (e.g. ctags -x --kinds-c=v --extras=-F file). ๐Ÿ”ฅ
  • --sort=(yes|no|foldcase) โ€” indicates whether the tag file should be sorted on the tag name (default is yes). Note that the original vi(1) required sorted tags. The foldcase value specifies case insensitive (or case-folded) sorting. Fast binary searches of tag files sorted with case-folding will require special support from tools using tag files, such as that found in the ctags readtags library, or Vim version 6.2 or higher (using set ignorecase). [Ignored in etags mode] ๐Ÿฆ‹
  • -u โ€” equivalent to --sort=no (i.e. "unsorted"). ๐Ÿ’€
  • --etags-include=<file> โ€” include a reference to <file> in the tag file. This option may be specified as many times as desired. This supports Emacs' capability to use a tag file which includes other tag files. [Available only in etags mode] ๐ŸŒธ
  • --input-encoding=<encoding> โ€” specifies the <encoding> of the input files. If this option is specified, Universal Ctags converts the input from this encoding to the encoding specified by --output-encoding=encoding. ๐Ÿงš
  • --input-encoding-<LANG>=<encoding> โ€” specifies a specific input <encoding> for <LANG>. It overrides the global default value given with --input-encoding. ๐Ÿ’œ
  • --output-encoding=<encoding> โ€” specifies the <encoding> of the tags file. Universal Ctags converts the encoding of input files from the encoding specified by --input-encoding=<encoding> to this encoding. In addition, <encoding> is specified at the top of the tags file as the value for the TAG_FILE_ENCODING pseudo-tag. The default value of <encoding> is UTF-8. โญ

๐ŸŒˆ Language Selection and Mapping Options ๐ŸŒˆ

  • --language-force=(<language>|auto) โ€” by default, ctags automatically selects the language of a source file, ignoring those files whose language cannot be determined (see "Determining file language"). 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 value auto indicates that the language should be automatically selected (which effectively disables this option). ๐Ÿ‘‘
  • --languages=[+|-](<list>|all) โ€” specifies the languages for which tag generation is enabled, with <list> containing a comma-separated list of language names (case-insensitive; either built-in or user-defined). If the first language of <list> is not preceded by either a + or -, the current list (the current settings of enabled/disabled languages managed in ctags internally) will be cleared before adding or removing the languages in <list>. 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 --langmap option). Note that the most of languages, including user-defined languages, are enabled unless explicitly disabled using this option. Language names included in list may 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-languages option for a list of the all (built-in and user-defined) language names. Note --languages= option works cumulative way; the option can be specified with different arguments multiple times in a command line. ๐Ÿ’…
  • --alias-<LANG>=[+|-](<pattern>|default) โ€” adds (+) or removes (-) an alias <pattern> to a language specified with <LANG>. ctags refers to the alias pattern in "Determining file language" stage. The parameter <pattern> is not a list. Use this option multiple times in a command line to add or remove multiple alias patterns. To restore the default language aliases, specify default. Using all for <LANG> has meaning in following two cases: --alias-all= clears aliases setting of all languages. --alias-all=default restores the default languages aliases for all languages. ๐ŸŽ€
  • --guess-language-eagerly โ€” looks into the file contents for heuristically guessing the proper language parser. See "Determining file language". ๐Ÿ”
  • -G โ€” equivalent to --guess-language-eagerly. ๐Ÿ˜Œ
  • --langmap=<map>[,<map>[...]] โ€” controls how file names are mapped to languages (see the --list-maps option). Each comma-separated <map> consists 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 --list-features option, 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 with --langmap option, it will first be unmapped from any other languages. (--map-<LANG> option provides more fine-grained control.) 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 one particular language โ€” which, yes, means ctags just stops auto-generating tags for it, bye bestie ๐Ÿ‘‹ โ€” you hand it an empty extension list, like --langmap=fortran:. Want the default mappings back for one language? Pass the keyword default for that mapping. And if you want to restore the default language mappings for all languages in one go, that's --langmap=default. ๐Ÿ’…

Ok but real talk ๐Ÿซถ โ€” when ctags is sniffing out what language a file is, it tests file name patterns before file extensions. Universal Ctags does it in this order, and Exuberant Ctags does not. It's genuinely different. Go read ctags-incompatibilities(7) if you want the whole backstory on this incompatible change. iykyk.
  • --map-<LANG>=[+|-]<extension>|<pattern> โ€” this is your fine-grained control for mapping file names to languages, way more precise than --langmap gives you.

In ctags, more than one language can map to a single file name <pattern> or file <extension> (that's an N:1 map). --langmap, by contrast, only handles a 1:1 map โ€” exactly one language to one file name <pattern> or file <extension>. The iconic N:1 example? C++ and ObjectiveC โ€” both of them map to .h as a file extension. Obsessed with the drama of it. ๐Ÿ˜ญ

You specify a file extension by putting a period in front of it (e.g. .c). You specify a file name pattern by wrapping it in parentheses (e.g. ([Mm]akefile)). A prefixed '+' sign means adding, a '-' means removing. No prefix at all means you're replacing the map of <LANG>.

Unlike --langmap, <extension> (or <pattern>) is not a list. --map-<LANG> takes one extension (or pattern), that's it. But here's the slay: you can specify the option with different arguments multiple times in a single command line. โœจ

๐ŸŽ€ TAGS FILE CONTENTS OPTIONS ๐ŸŽ€

See "TAG ENTRIES" about fields, kinds, roles, and extras.

  • --excmd=(number|pattern|mix|combine) โ€” decides what type of EX command gets 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:
    1. Significantly reduces the size of the resulting tag file.
    2. 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).
    3. Eliminates finding identical matching, but incorrect, source lines (see "BUGS").
    4. 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: -B, -F.

number type is ignored in Xref and JSON output formats. Use --_xformat="...%n" for Xref output format, or --fields=+n-P for JSON output format.

  • 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. ๐Ÿฆ‹
  • mixed โ€” in this mode, patterns are generally used, with an exceptions. 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.

Exuberant Ctags has one more exception: for C, line numbers are used for macro definition tags. Universal Ctags doesn't have this exception for C.

This was the default format generated by the original ctags and is, therefore, retained as the default for this option. Main character energy fr fr. ๐Ÿ‘‘

  • combine โ€” concatenate the line number and pattern with a semicolon in between.
  • -n โ€” equivalent to --excmd=number.
  • -N โ€” equivalent to --excmd=pattern.

  • --extras=[+|-][<flags>|*] โ€” specifies whether to include extra tag entries for certain kinds of information. See also the "Extras" subsection to know what extras even are. ๐Ÿ™ˆ

The parameter <flags> is a set of one-letter flags (and/or long-name 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. All entries are included if '*' is given.

This --extras= option is for controlling extras common in all languages (or language-independent extras). Universal Ctags also supports language-specific extras. (See "Language-specific fields and extras" about the concept.) Use --extras-<LANG>= option for controlling them.

  • --extras-(<LANG>|all)=[+|-][<flags>|*] โ€” specifies whether to include extra tag entries for certain kinds of information for language <LANG>. Universal Ctags introduces language-specific extras. See "Language-specific fields and extras" about the concept. This option is for controlling them.

Specify all as <LANG> to apply the parameter <flags> to all languages; all extras are enabled with specifying '*' as the parameter flags. If you specify nothing as the parameter flags (--extras-all=), all extras are disabled. These two combinations are useful for testing. ๐Ÿงš

Check the output of the --list-extras=<LANG> option for the extras of a specific language <LANG>.

  • --fields=[+|-][<flags>|*] โ€” specifies which language-independent fields are to be included in the tag entries. Language-independent fields are extension fields which are common in all languages. See the "TAG FILE FORMAT" section, and the "Extension fields" subsection, for details of extension fields.

The parameter <flags> is a set of one-letter or long-name flags, each representing one type of extension field to include. Each flag or group of flags 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 fields explicitly listed in flags will be included in the output (i.e. overriding the default set). All fields are included if '*' is given.

This option is ignored if the option --format=1 (legacy tag file format) has been specified.

Use --fields-<LANG>= option for controlling language-specific fields.

  • --fields-(<LANG>|all)=[+|-][<flags>|*] โ€” specifies which language-specific fields are to be included in the tag entries. Universal Ctags supports language-specific fields. (See "Language-specific fields and extras" about the concept.)

Specify all as <LANG> to apply the parameter <flags> to all languages; all fields are enabled with specifying '*' as the parameter flags. If you specify nothing as the parameter <flags> (i.e. --fields-all=), all fields are disabled. These two combinations are useful for testing.

See the description of --fields=[+|-][<flags>|*] about <flags>.

Use --fields= option for controlling language-independent fields.

  • --kinds-(<LANG>|all)=[+|-](<kinds>|*) โ€” specifies a list of language-specific <kinds> of tags (or 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 (see the --list-languages option for a complete list).

The parameter <kinds> is a group of one-letter or long-name 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-kinds-full option.

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 in kinds will be included in the output (i.e. overriding the default for the specified language).

Specify '*' as the parameter to include all kinds implemented in <LANG> in the output. Furthermore, if all is given as <LANG>, specification of the parameter kinds affects all languages defined in ctags. Giving all makes sense only when '*' or 'F' is given as the parameter kinds.

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 --kinds-c=+px-d; to include only tags for functions, use --kinds-c=f.

Some kinds of C and C++ languages are synchronized; enabling (or disabling) a kind in one language enables the kind having the same one-letter and long-name in the other language. See also the description of the MASTER column of --list-kinds-full. ๐Ÿ”ฅ

  • --pattern-length-limit=<N> โ€” truncate patterns of tag entries after <N> characters. Disable by setting to 0 (default is 96).

An input source file with long lines and multiple tag matches per line can generate an excessively large tags file with an unconstrained pattern length. For example, running ctags on a minified JavaScript source file often exhibits this behavior. ๐Ÿ˜ญ

Okay so real talk about that truncation thing ๐Ÿ’… โ€” it never cuts in the middle of a UTF-8 code point that spans multiple bytes, because writing invalid byte sequences from valid input files is not the vibe. This handling lets you sneak an extra 3 bytes above the configured limit in the worse case, i.e. when a 4 byte code point starts right before the limit. โœจ

And bestie, please also note that this handling is fairly naive and fast, and even though it's resistant against any input, it requires a valid input to work properly; it is not guaranteed to work as the user expects when dealing with partially invalid UTF-8 input. ๐Ÿซ  This also partially affect non-UTF-8 input, if the byte sequence at the truncation length looks like a multibyte UTF-8 sequence. That should however be rare, and in the worse case will lead to including up to an extra 3 bytes above the limit. ๐Ÿ’€

  • --pseudo-tags=[+|-](<pseudo-tag>|*) โ€” turn emitting the pseudo-tag named pseudo-tag on or off. And if you hand it '*'? That's the all-of-them button, bestie: enable/disable emitting all pseudo-tags. ๐Ÿ‘‘
  • --put-field-prefix โ€” slaps UCTAGS as a prefix onto the name of fields newly introduced in Universal Ctags. ๐ŸŽ€

Some fields are newly introduced in Universal Ctags and more will be introduced in the future. Other tags generators may also introduce their specific fields.

And in such a situation, there's a whole concern about conflicting field names; mixing tags files generated by multiple tags generators including Universal Ctags is difficult. This option is the workaround for that station, periodt.

   $ ctags --fields='{line}{end}' -o - hello.c
   main    hello.c /^main(int argc, char **argv)$/;"       f       line:3  end:6
   $ ctags --put-field-prefix --fields='{line}{end}' -o - hello.c
   main    hello.c /^main(int argc, char **argv)$/;"       f       line:3  UCTAGSend:6

In the above example, the prefix is put to end field which is newly introduced in Universal Ctags. See how the glow-up happened? ๐ŸŒˆ

  • --roles-(<LANG>|all).(<kind>|*)=[+|-][<roles>|*] โ€” specifies a list of kind-specific roles of tags to include in the output file for a particular language. kind specifies the kind where the roles are defined. LANG specifies the language where the kind is defined. And every single role in roles must be surrounded by braces (e.g. {system} for a role named "system"). No braces, no entry, iykyk. ๐ŸŽ€

Like the --kinds-<LANG> option, '+' is for adding the role to the list, and '-' is for removing from the list. '*' is for including all roles of the kind to the list. The option with no argument makes the list empty. ๐Ÿ™ˆ

Both a one-letter flag or a long name flag surrounded by braces are acceptable for specifying a kind (e.g. --roles-C.h=+{system}{local} or --roles-C.{header}=+{system}{local}). '*' can be used for KIND only for adding/removing all roles of all kinds in a language to/from the list (e.g. --roles-C.*=* or --roles-C.*=).

all can be used for LANG only for adding/removing all roles of all kinds in all languages to/from the list (e.g. --roles-all.*=* or --roles-all.*=). That's the everything-everywhere option, lowkey iconic. ๐Ÿ’…

  • --tag-relative=(yes|no|always|never) โ€” specifies how the file paths recorded in the tag file. The default is yes when running in etags mode (see the -e option), no otherwise. ๐Ÿ‘€
    • yes โ€” indicates that the file paths recorded in the tag file should be relative to the directory containing the tag file unless the files supplied on the command line are specified with absolute paths.
    • no โ€” indicates that the file paths recorded in the tag file should be relative to the current directory unless the files supplied on the command line are specified with absolute paths.
    • always โ€” indicates the recorded file paths should be relative even if source file names are passed in with absolute paths.
    • never โ€” indicates the recorded file paths should be absolute even if source file names are passed in with relative paths.
  • --use-slash-as-filename-separator[=(yes|no)] โ€” uses the slash ('/') character as filename separators instead of the backslash ('\') character when printing the input: field. The default is yes for the default "u-ctags" output format, and no for the other formats. ๐Ÿฆ‹

The TAG_OUTPUT_FILESEP pseudo tag is for representing the choice of filename separators with this option. See also ctags-client-tools(7).

This option is available on MS Windows only. ๐ŸชŸ
  • -B โ€” use backward searching patterns (e.g. ?pattern?). [Ignored in etags mode]
  • -F โ€” use forward searching patterns (e.g. /pattern/) (default). [Ignored in etags mode]

๐Ÿ“ Option File Options ๐Ÿ“

  • --options=<pathname> โ€” read additional options from file or directory. ๐Ÿ—‚๏ธ

ctags searches pathname in the optlib path list first. If ctags cannot find a file or directory in the list, ctags reads a file or directory at the specified pathname.

If a file is specified, it should contain one option per line. If a directory is specified, files suffixed with .ctags under it are read in alphabetical order. ๐Ÿ”ค

As a special case, if --options=NONE is specified as the first option on the command line, preloading is disabled; the option will disable the automatic reading of any configuration options from a file (see "FILES"). ๐Ÿšซ

  • --options-maybe=<pathname> โ€” same as --options but doesn't cause an error if the file (or directory) specified with pathname doesn't exist. Chill vibes only, no drama. ๐Ÿซถ
  • --optlib-dir=[+]<directory> โ€” add an optlib directory to or reset the optlib path list. See "Default optlib path list" about the default elements for the optlib path list. ๐Ÿ“š

๐Ÿงš optlib Options ๐Ÿงš

See ctags-optlib(7) for details of each option. ๐Ÿ’œ

  • --kinddef-<LANG>=<letter>,<name>,<description> โ€” define a kind for LANG. Don't be confused this with --kinds-<LANG>. (They are not the same bestie, I promise. ๐Ÿ˜ญ)
  • --langdef=<name> โ€” defines a new user-defined language, name, to be parsed with regular expressions. โœจ
  • --mline-regex-<LANG>=/<line_pattern>/<name_pattern>/<kind-spec>/[<flags>] โ€” define multi-line regular expression for locating tags in specific language. ๐Ÿ”
  • --regex-<LANG>=/<line_pattern>/<name_pattern>/<kind-spec>/[<flags>] โ€” define single-line regular expression for locating tags in specific language. ๐Ÿ”Ž

๐ŸŒธ Language Specific Options ๐ŸŒธ

  • --if0[=(yes|no)] โ€” indicates a preference as to whether code within an "#if 0" branch of a preprocessor conditional should be examined for non-macro tags (macro tags are always included). Because the intent of this construct is to disable code, the default value of this option is no (disabled). ๐Ÿšซ
Note that this indicates a preference only and does not guarantee skipping code within an "#if 0" branch, since the fall-back algorithm used to generate tags when preprocessor conditionals are too complex follows all branches of a conditional. ๐Ÿ™ƒ
  • --line-directives[=(yes|no)] โ€” specifies whether #line directives should be recognized. These are present in the output of a preprocessor and contain the line number, and possibly the file name, of the original source file(s) from which the preprocessor output file was generated. This option is off by default. ๐Ÿ’ค

When enabled, this option will cause ctags to 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 #line directive specifies an absolute path). ๐Ÿ›ค๏ธ

Note: This option is generally only useful when used together with the --excmd=number (-n) option. Also, you may have to use either the --langmap or --language-force option if the extension of the preprocessor output file is not known to ctags. ๐Ÿ‘‘
  • -D <macro>=<definition> โ€” defines a C preprocessor macro. This emulates the behavior of the corresponding gcc option. All types of macros are supported, including the ones with parameters and variable arguments. Stringification, token pasting and recursive macro expansion are also supported. This extends the function provided by the -I option. ๐Ÿ”ฅ
  • -h (<list>|default) โ€” 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 particular kinds of tags are interpreted (i.e. whether or not they are considered as globally visible or visible only within the file in which they are defined); it does not map the extension to any particular language. Any tag which is located in a non-include file and cannot be seen (e.g. linked to) from another file is considered to have file-limited (e.g. static) scope. No kind of tag appearing in an include file will be considered to have file-limited scope. ๐Ÿ‘€

If the first character in the list is '+', then the extensions in the list will be appended to the current list; otherwise, the list will replace the current list. See, also, the fileScope/F flag of --extras 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 "Determining file language", above), you will also need to use either the --map-<LANG>, --langmap or --language-force option. ๐Ÿ˜ญ
  • -I <identifier-list> โ€” specifies an identifier-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. ๐ŸŽ€

Okay so if an identifier has a little + tacked on the end (like -I FOO+), ctags is also gonna ignore any parenthesis-wrapped argument list that shows up right after that identifier in your source files. There's a whole example of -I MODULE_VERSION+ chillin' below, bestie. ๐Ÿ‘€

And if two identifiers are separated by the = character (like -I FOO=BAR), then the first identifier gets swapped out for the second one, just for parsing purposes. The identifier list can come straight from the command line or you can read it in from a separate file. See the -I CLASS=class example down below for the vibe. โœจ

Now, if the very first character of <identifier-list> is @, ., or a pathname separator (/ or \), or if the first two characters spell out a drive letter (like C:), then <identifier-list> gets interpreted as a filename to read a list of identifiers from, one per input line. ๐Ÿ“„

Otherwise, <identifier-list> is just a list of identifiers (or identifier pairs) you want specially handled, each one separated by a comma or by whitespace โ€” and in the whitespace case you gotta quote the whole thing so it stays as one single command line argument, iykyk.

You can pass multiple -I options. And to clear the whole list of ignore identifiers, just hand it a single dash (-) for <identifier-list>. Poof, gone. ๐Ÿ’…

This feature is chef's kiss when preprocessor macros are being used in a way that makes everything syntactically confusing just by existing. Fr fr, this is the best way to work around a whole bunch of problems caused by syntax-busting macros hanging out in your source files (peep "CAVEATS" for more). Let's look at some examples that really illustrate the point. ๐ŸŽ€

   int foo ARGDECL4(void *, ptr, long int, nbytes)

So in the above, the macro ARGDECL4 would get mistakenly read as the name of the function instead of the correct name, foo. Specifying -I ARGDECL4 gives you the correct behavior. Slay.

   /* creates an RCS version string in module */
   MODULE_VERSION("$Revision$")

Here the macro invocation looks way too much like a function definition, because it's not followed by a semicolon (and honestly it could even be followed by a global variable definition that looks 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 ctags is trying to complete the definition. Specifying -I MODULE_VERSION+ avoids that whole problem. ๐Ÿซถ

   CLASS Example {
           // your content here
   };

The example above uses CLASS as a preprocessor macro that expands to something different on each platform. For instance, CLASS might be defined as class __declspec(dllexport) on Win32 platforms and just plain class on UNIX. Normally, the absence of the C++ keyword class would make the source file get parsed incorrectly. You can restore correct behavior by specifying -I CLASS=class. ๐Ÿ’–

  • --param-<LANG>.<name>=<argument> โ€” sets a <LANG> specific parameter, aka a parameter specific to the <LANG>. ๐ŸŒธ

The parameters that are available can be listed with --list-params.


โœจ Listing Options โœจ

  • --list-aliases[=(<language>|all)] โ€” lists the aliases for either the <language> you named or all languages, then dips out (exits). all is the default value if you don't give the option an argument. The aliases get used when heuristically testing a language parser against a source file. ๐Ÿฆ‹
  • --list-excludes โ€” lists the current exclusion patterns used to exclude files. ๐Ÿšซ
  • --list-extras[=(<language>|NONE|all)] โ€” lists the extras recognized for either the specified <language> or all languages. If you say NONE, it lists only the extras that are common in all languages. Peep the "Extras" subsection to learn what extras even are. all is the default value if the option argument is omitted. โœจ

An extra can be turned on or off with --extras= for common extras in all languages, or --extras-<LANG>= for the specified language. These options take a one-letter flag or a long-name flag as a parameter to specify an extra.

The meaning of the columns in the output is as follows:

  • LETTER โ€” the one-letter flag. A - means the extra doesn't have a one-letter flag.
  • NAME โ€” the long-name flag. The long-name is used in the extras field.
  • ENABLED โ€” whether the extra is enabled or not. It takes yes or no.
  • LANGUAGE โ€” the name of the language if the extra is owned by a parser. NONE means the extra is common in parsers.
  • DESCRIPTION โ€” a human readable description for the extra.
  • --list-features โ€” lists the compiled features. ๐ŸŒˆ
  • --list-fields[=(<language>|NONE|all)] โ€” lists the fields recognized for either the specified <language> or all languages. If NONE is specified, it lists only the fields common in all languages. See the "Extension fields" subsection to learn what fields are. all is the default value if the option argument is omitted. ๐Ÿ“

The meaning of the columns is as follows:

  • LETTER โ€” the one-letter flag. A - means the field doesn't have a one-letter flag.
  • NAME โ€” the long-name of the field.
  • ENABLED โ€” whether the field is enabled or not. It takes yes or no.
  • LANGUAGE โ€” the name of the language if the field is owned by a parser. NONE means the field is a language-independent field that's common in all languages.
  • JSTYPE โ€” the JSON type used when printing the value of the field when --output-format=json is specified. See ctags-client-tools(7).
  • FIXED โ€” whether this field can be disabled or not in tags output.

Some fields are printed always in tags output. They have yes as the value for this column.

Unlike the tag output mode, JSON output mode lets you disable any fields. ๐Ÿ’…

  • OP โ€” how this field can be accessed from optscript code. This field is for Universal Ctags developers. ๐Ÿ› ๏ธ
  • DESCRIPTION โ€” a human readable description for the field.
  • --list-kinds[=(<language>|all)] โ€” a subset of --list-kinds-full. This option is kept around for backward-compatibility with Exuberant Ctags.

This option prints only the LETTER, DESCRIPTION, and ENABLED fields of --list-kinds-full output. But the presentation of the ENABLED column is different from that of the --list-kinds-full option; [off] follows after the description if the kind is disabled, and nothing follows if it's enabled. The most of all kinds are enabled by default.

The critical weakness of this option is that it does not print the name of the kind. Universal Ctags introduced --list-kinds-full because it considers that names are important. ๐Ÿ‘‘

This option does not work with --machinable nor --with-list-header. ๐Ÿ’€

  • --list-kinds-full[=(<language>|all)] โ€” lists the tag kinds recognized for either the specified <language> or all languages, then exits. See the "Kinds" subsection to learn what kinds are. all is the default value if the option argument is omitted. ๐ŸŽ€

Each kind of tag recorded in the tag file is represented by a one-letter flag, or a long-name flag. They're also used to filter the tags placed into the output through the --kinds-<LANG> option.

The meaning of the columns is as follows:

  • LANGUAGE โ€” the name of the language having the kind.
  • LETTER โ€” the one-letter flag. This must be unique in a language.
  • NAME โ€” the long-name flag of the kind. This can be used as the alternative to the one-letter flag described above. If you enable the K field with --fields=+K, ctags uses long-names instead of one-letters in tags output. To enable/disable a kind with the --kinds-<LANG> option, use the long-name surrounded by braces instead of the one-letter. See "Letters and names" for details. This must be unique in a language.
  • ENABLED โ€” whether the kind is enabled or not. It takes yes or no.
  • REFONLY โ€” whether the kind is specialized for reference tagging or not. If the column is yes, the kind is for reference tagging, and it is never used for definition tagging. See also "TAG ENTRIES". ๐Ÿ”–
  • NROLES โ€” the number of roles this kind has. See also "Roles".
  • MASTER โ€” the master parser controlling enablement of the kind. A kind belongs to a language (owner) in Universal Ctags; enabling and disabling a kind in a language has no effect on a kind in another language, even if both kinds have the same one-letter flag and/or the same long-name flag. In other words, the namespace of kinds are separated by language.

However, Exuberant Ctags does not separate the kinds of C and C++. Enabling/disabling kindX in the C language enables/disables a kind in the C++ language that has the same long-name flag with kindX. To emulate this behavior in Universal Ctags, a concept named master parser was introduced. Enabling/disabling some kinds are synchronized under the control of a master language.

$ ctags --kinds-C=+'{local}' --list-kinds-full \
  | grep -E '^(#|C\+\+ .* local)'
#LANGUAGE  LETTER NAME   ENABLED REFONLY NROLES MASTER DESCRIPTION
C++        l      local  yes     no      0      C      local variables
$ ctags --kinds-C=-'{local}' --list-kinds-full \
  | grep -E '^(#|C\+\+ .* local)'
#LANGUAGE  LETTER NAME   ENABLED REFONLY NROLES MASTER DESCRIPTION
C++        l      local  no      no      0      C      local variables

You see the ENABLED field of the local kind of the C++ language is changed, though the local kind of the C language is what got enabled/disabled. If you swap the languages, you see the same result. ๐Ÿคฏ

  • DESCRIPTION โ€” a human readable description for the kind.
  • --list-languages โ€” drops the names of every language ctags knows how to parse, then dips out. These language names are case insensitive and you can use them in a whole bunch of other options like --language-force, --languages, --kinds-<LANG>, --regex-<LANG>, and so on. iykyk ๐Ÿ’…

Each language in the list is disabled if it's followed by [disabled]. Wanna actually use the parser for one of those? Pass the language as an argument to the --languages=+ option, bestie. โœจ

Also, heads up: --machinable and --with-list-header are ignored if you specify them alongside this option. no cap.

  • --list-map-extensions[=(<language>|all)] โ€” lists the file extensions that associate a file name with a language, for either the specified <language> or all languages, and then exits. If you skip the option argument, all is used as the default value. ๐ŸŒˆ
  • --list-map-patterns[=(<language>|all)] โ€” lists the file name patterns that associate a file name with a language, for either the specified <language> or all languages, and then exits. Omit the argument and all is the default value, fr fr. ๐Ÿฆ‹
  • --list-maps[=(<language>|all)] โ€” lists both the file name patterns and the file extensions that associate a file name with a language, for either the specified <language> or all languages, and then exits. Yep, all is the default if you don't pass an argument. ๐Ÿ‘‘

Wanna list the file extensions or the file name patterns one at a time instead? Use the --list-map-extensions or --list-map-patterns option. Also peep the --langmap option, and "Determining file language", above. ๐Ÿ“–

โš ๏ธ This option does not work with --machinable nor --with-list-header. periodt.
  • --list-mline-regex-flags โ€” outputs the list of flags you can use in a multiline regex parser definition. See ctags-optlib(7). ๐Ÿ’œ
  • --list-output-formats โ€” lists the output formats you can use in the --output-format option. โœจ

The NULLTAG column represetns whether the format supports null tags or not. See nulltag/z in "Extras" about the null tags. ๐Ÿ‘€

(since verison 6.2.0) ๐ŸŽ€

  • --list-params[=(<language>|all)] โ€” lists the parameters for either the specified <language> or all languages, and then exits. all is the default value when you don't give the option an argument. ๐ŸŒธ
  • --list-pseudo-tags โ€” outputs the list of pseudo-tags. that's it, that's the vibe. ๐Ÿ’ซ
  • --list-regex-flags โ€” lists the flags that can be used in the --regex-<LANG> option. See ctags-optlib(7). ๐Ÿ”ฅ
  • --list-roles[=(<language>|all)[.(<kind-specs>|*)] ] โ€” lists the roles for either the specified <language> or all languages. all is used as the default value if the option argument is omitted. ๐Ÿ’–

If the parameter <kindspecs> is given after the parameter <language> or all, concatenated with a ., it lists only the roles defined in those kinds. Both one-letter flags and long name flags surrounded by braces are acceptable as the parameter <kindspecs>, bestie. ๐Ÿซถ

Here's what each column means:

  • LANGUAGE โ€” the name of the language that has the role. ๐ŸŒ
  • KIND(L/N) โ€” the one-letter flag and the long-name flag of the kind that has the role. ๐Ÿ”ค
  • NAME โ€” the long-name flag of the role. ๐Ÿท๏ธ
  • ENABLED โ€” whether the kind is enabled or not. It takes yes or no. โœ…
  • DESCRIPTION โ€” a human readable description for the role. ๐Ÿ’ฌ
  • --list-subparsers[=(<baselang>|all)] โ€” lists the subparsers for a base language, for either the specified <baselang> or all languages, and then exits. all is the default value if the option argument is omitted. ๐Ÿงš
  • --machinable[=(yes|no)] โ€” uses the tab character as separators for --list- option output. Lowkey perfect for scripting. See "List options" for considered use cases. Disabled by default. ๐Ÿ–ฅ๏ธ
  • --with-list-header[=(yes|no)] โ€” prints headers describing the columns in --list- option output. See also "List options". ๐Ÿ“Š

๐ŸŒธ Miscellaneous Options ๐ŸŒธ

  • --help โ€” prints to standard output a detailed usage description, and then exits. the moment you need it most ๐Ÿ’…
  • -? โ€” equivalent to --help. ๐ŸŽ€
  • --help-full โ€” prints to standard output a detailed usage description including experimental features, and then exits. Visit <https://docs.ctags.io/> for info about the latest exciting experimental features. it's giving main character energy โœจ
  • --license โ€” prints a summary of the software license to standard output, and then exits. ๐Ÿ“œ
  • --print-language โ€” just prints the language parsers for the specified source files, and then exits. ๐Ÿฆ‹
  • --quiet[=(yes|no)] โ€” writes fewer messages (default is no). shhh ๐Ÿคซ
  • --totals[=(yes|no|extra)] โ€” prints statistics about the source files read and the tag file written during the current invocation of ctags. This option is no by default. ๐Ÿ“ˆ

The extra value prints parser specific statistics for parsers that gather such information. ๐Ÿ”

  • --verbose[=(yes|no)] โ€” enables verbose mode. This prints out info on option processing, plus a brief message describing what action is being taken for each file considered by ctags. Normally, ctags does not read command line arguments until after options are read from the configuration files (see "FILES", below). However, if this option is the first argument on the command line, it takes effect before any options are read from these sources. The default is no. ๐Ÿ—ฃ๏ธ
  • -V โ€” equivalent to --verbose. ๐Ÿ’ฌ
  • --version[=<language>|NONE] โ€” prints a version identifier for ctags to standard output, and then exits. This is guaranteed to always contain the string "Universal Ctags". See also the description for TAG_PROGRAM_VERSION and TAG_OUTPUT_VERSION in ctags-client-tools(7). โญ

If NONE is given, it prints the version identifier in a simplified way. ๐Ÿช„

If <language> is given, it prints the version identifier for the parser for <language>. See also the description for TAG_PARSER_VERSION in ctags-client-tools(7). ๐Ÿ”ฎ


๐Ÿ’€ Obsoleted Options ๐Ÿ’€

These options are kept around for backward-compatibility with Exuberant Ctags. they're the vintage collection, bestie ๐Ÿ•ฐ๏ธ

  • -w โ€” this option is silently ignored for backward-compatibility with the ctags of SVR4 Unix. ๐Ÿ™ˆ
  • --file-scope[=(yes|no)] โ€” this option is removed. Use --extras=[+|-]F or --extras=[+|-]{fileScope} instead. โš ๏ธ
  • --extra=[+|-][<flags>|*] โ€” equivalent to --extras=[+|-][<flags>|*], which was introduced to make the option naming convention align with the other options like --kinds-<LANG>= and --fields=. ๐Ÿ’ซ
  • --<LANG>-kinds=[+|-](<kinds>|*) โ€” this option is obsolete. Use --kinds-<LANG>=... instead. ๐Ÿšซ

๐Ÿ” OPERATIONAL DETAILS ๐Ÿ”

okay so here's the actual tea on what ctags does when you run it, bestie. As ctags considers each source file name in turn, it tries to figure out the language of the file by applying the tests described in "Determining file language".

If a language was 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 is written to handle. See "TAG FILE FORMAT", below, for details on these entries. โœจ


๐Ÿ’ป Notes for C/C++ Parser ๐Ÿ’ป

This implementation of ctags imposes no formatting requirements on C code as do legacy implementations. Older implementations of ctags tended to rely upon certain formatting assumptions in order to help it resolve coding dilemmas caused by preprocessor conditionals. ๐Ÿ’€ (the way those old ones needed training wheelsโ€ฆ)

In general, ctags tries to be smart about conditional preprocessor directives. If a preprocessor conditional is encountered within a statement which defines a tag, ctags follows only the first branch of that conditional (except in the special case of #if 0, in which case it follows only the last branch). The reason for this is that failing to pursue only one branch can result in ambiguous syntax, as in the following 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 the application of this heuristic fails to properly parse a file, generally due to complicated and inconsistent pairing within the conditionals, ctags will retry the file using a different heuristic which does not selectively follow conditional preprocessor branches, but instead 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 arguments lists enclosed in double sets of parentheses in order to accept the following 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. ๐Ÿ™ˆ

C++ operator definitions are specially handled. In order for consistency with 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 is sorted by the tag name, removing identical tag lines.


๐Ÿงš Determining file language ๐Ÿงš

File name mapping

Unless the --language-force option is specified, the language of each source file is automatically selected based upon a mapping of file names to languages. The mappings in effect for each language may be displayed using the --list-maps option and may be changed using the --langmap or --map-<LANG> options.

If the name of a file is not mapped to a language, ctags tries to heuristically guess the language for the file by inspecting its content.

All files that have no file name mapping and no guessed parser are ignored. This permits running ctags on all files in either a single directory (e.g. "ctags *"), or on all files in an entire source directory tree (e.g. "ctags -R"), since only those files whose names are mapped to languages will be scanned. ๐ŸŒˆ

An extension may be mapped to multiple parsers. For example, .h are mapped to C++, C and ObjectiveC. These mappings can cause issues. ctags tries to select the proper parser for the source file by applying heuristics to its content, however it is not perfect. In case of issues one can use --language-force=<language>, --langmap=<map>[,<map>[...]], or the --map-<LANG>=[+|-]<extension>|<pattern> options. (Some of the heuristics are applied whether --guess-language-eagerly is given or not.)

Heuristically guessing

If ctags cannot select a parser from the mapping of file names, various heuristic tests are conducted to determine the language:

template file name testing

If the file name has an .in extension, ctags applies the mapping to the file name without the extension. For example, config.h is tested for a file named config.h.in.

"interpreter" testing

The first line of the file is checked to see if the file is a #! script for a recognized language. ctags looks for a parser having the same name.

If ctags finds no such parser, ctags looks for the name in alias lists. For example, consider if the first line is #!/bin/sh. Though ctags has a "shell" parser, it doesn't have a "sh" parser. However, sh is listed as an alias for shell, therefore ctags selects the "shell" parser for the file.

An exception is env. If env is specified (for example "#!/usr/bin/env python"), ctags reads more lines to find real interpreter specification.

To display the list of aliases, use --list-aliases option. To add an item to the list or to remove an item from the list, use the --alias-<LANG>=+<pattern> or --alias-<LANG>=-<pattern> option respectively.

"zsh autoload tag" testing

If the first line starts with #compdef or #autoload, ctags regards the line as "zsh".

"emacs mode at the first line" testing

The Emacs editor has multiple editing modes specialized for programming languages. Emacs can recognize a marker called modeline in a file and utilize the marker for the mode selection. This heuristic test does the same as what Emacs does.

ctags treats MODE as a name of interpreter and applies the same rule of "interpreter" testing if the first line has one of the following patterns:

-*- mode: MODE -*-

or

-*- MODE -*-

"emacs mode at the EOF" testing

Emacs editor recognizes another marker at the end of file as a mode specifier. This heuristic test does the same as what Emacs does.

ctags treats MODE as a name of an interpreter and applies the same rule of "interpreter" heuristic testing, if the lines at the tail of the file have the following pattern:

Local Variables:
...
mode: MODE
...
End:

3000 characters are sought from the end of file to find the pattern. ๐Ÿ”ฅ

"vim modeline" testing

Like the modeline of the Emacs editor, Vim editor has the same concept. ctags treats TYPE as a name of interpreter and applies the same rule of "interpreter" heuristic testing if the first or last 5 lines of the file have one of the following patterns:

filetype=TYPE

or

ft=TYPE

"PHP marker" testing

If the first line is started with <?php, ctags regards the line as "php".


Looking into the file contents is a more expensive operation than file name matching. So ctags runs the testings in limited conditions. "interpreter" testing is enabled only when a file is an executable or the --guess-language-eagerly (-G in short) option is given. The other heuristic tests are enabled only when -G option is given.

The --print-language option can be used just to print the results of parser selections for given files instead of generating a tags file.

Examples:

$ ctags --print-language config.h.in input.m input.unknown
config.h.in: C++
input.m: MatLab
input.unknown: NONE

NONE means that ctags does not select any parser for the file. ๐Ÿซถ


๐ŸŽ€ TAG FILE FORMAT ๐ŸŽ€

This section describes the tag file format briefly. See tags(5) and ctags-client-tools(7) for more details.

When not running in etags mode, each entry in the tag file consists of a separate line, each looking like this, called regular tags, in the most general case:

<tag_name><TAB><file_name><TAB><ex_cmd>;"<TAB><extension_fields>

The fields and separators of these lines are specified as follows:

  1. <tag_name>: tag name
  2. <TAB>: single tab character
  3. <file_name>: name of the file in which the object associated with the tag is located
  4. <TAB>: single tab character
  5. <ex_cmd>: EX command used to locate the tag within the file; generally a search pattern (either /pattern/ or ?pattern?) or line number (see --excmd=<type> option).
  6. ;"<TAB><extension_fields: a set of extension fields. See "Extension fields" for more details.

Tag file format 2 (see --format) extends the EX command to include the extension fields embedded in an EX comment immediately appended to the EX command, which leaves it backward-compatible with original vi(1) implementations. ๐Ÿ’…

A few special tags, called pseudo tags, are written into the tag file for internal purposes.

!_TAG_FILE_FORMAT       2       /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED       1       /0=unsorted, 1=sorted, 2=foldcase/
...

--pseudo-tags=[+|-](<pseudo-tag>|*) option enables or disables emitting pseudo-tags.

See the output of "ctags --list-pseudo-tags" for the list of the kinds. See also tags(5) and ctags-client-tools(7) for more details of the pseudo tags.

These tags are composed in such a way that they always sort to the top of the file. Therefore, the first two characters of these tags are used a magic number to detect a tag file for purposes of determining whether a valid tag file is being overwritten rather than a source file. ๐Ÿ˜ฑ

Note that the name of each source file will be recorded in the tag file exactly as it appears on the command line. Therefore, if the path you specified on the command line was relative to the current directory, then it will be recorded in that same manner in the tag file. See, however, the --tag-relative=(yes|no|always|never) option for how this behavior can be modified.

๐ŸŒธ TAG ENTRIES ๐ŸŒธ

A tag is an index for a language object. The concept of a tag and related items in Exuberant Ctags are refined and extended in Universal Ctags. ๐Ÿ‘‘

A tag is categorized into definition tags or reference tags. In general, Exuberant Ctags only tags definitions of language objects: places where newly named language objects are introduced. Universal Ctags, on the other hand, can also tag references of language objects: places where named language objects are used. However, support for generating reference tags is new and limited to specific areas of specific languages in the current version.

โœจ Extension fields โœจ

A tag can record various information, called extension fields.

Okay bestie, we're still in the tag-entry-nerd zone, and honestly? This is where it gets good. ๐Ÿ’…

Extension fields are tab-separated key-value pairs that get tacked onto the end of the EX command, like a little comment, exactly as described above. They show up in the general form key:value. ๐Ÿ’–

On top of that, you might get info about the scope of a tag definition โ€” where the key part is some language-dependent construct name and the value is the name declared for that construct in the program. This scope entry tells you where the tag was found. For example, a tag generated for a C structure member would have a scope looking like struct:myStruct. ๐ŸŽ€

The --fields=[+|-][<flags>|*] and --fields-(<LANG>|all)=[+|-][<flags>|*] options tell ctags which available extension fields to include in the tag entries. โœจ

Go peek at the output of ctags --list-fields for the full list of extension fields. The essential ones are name, input, pattern, and line. Here's what the major fields mean, shown as (long-name flag / one-letter flag): ๐Ÿ‘‘

  • access/a โ€” shows the visibility of this class member, where the value is specific to the language. ๐Ÿซถ
  • end/e โ€” the line number of the end lines of the language object.
  • extras/E โ€” extra tag type information. See "Extras" for the deets. ๐Ÿ’€
  • file/f โ€” says this tag has file-limited visibility. This key has no corresponding value. Enabled by default.
  • implementation/m โ€” when present, says there's 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/i โ€” when present, the value is a comma-separated list of classes this class is derived from (i.e. inherits from). ๐ŸŒธ
  • input/F โ€” the name of the source file where name is defined or referenced.
  • k โ€” Kind <Kinds> of tag as one-letter. Enabled by default. This field has no long-name. See also the kind/z flag.
  • K โ€” Kind <Kinds> of tag as long-name. This field has no long-name. See also the kind/z flag.
  • kind/z โ€” include the kind: key in the kind field <Kinds>. See also the k and K flags.
  • language/l โ€” language of the source file containing the tag.
  • line/n โ€” the line number where name is defined or referenced in input.
  • name/N โ€” the name of language objects.
  • nth/o โ€” the order in the parent scope (i.e. the 4th parameter in the function). ๐Ÿ”ข
  • pattern/P โ€” can be used to search the name in input.
  • roles/r โ€” roles assigned to the tag. See "Roles" for way more detail.
  • s โ€” scope of tag definition. Enabled by default. This field has no long-name. See also the scope/Z flag.
  • scope/Z โ€” prepend the scope: key to the scope (s) field. See also the s flag.
  • scopeKind/p โ€” kind of scope as long-name.
  • signature/S โ€” when present, the value is a language-dependent representation of the signature of a routine (e.g. prototype or parameter list). 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.
  • typeref/t โ€” type and name of a variable, typedef, or return type of a callable like a function, as a typeref: field. Enabled by default.

โœจ Kinds โœจ

kind is a field that represents the kind of language object a tag points at. And bestie, the kinds used and defined are wildly different between parsers. Like, C defines macro, function, variable, typedef, etc. ๐ŸŒˆ

The --kinds-(<LANG>|all)=[+|-](<kinds>|*) option specifies a list of language-specific kinds of tags (or kinds) to include in the output file for a particular language. ๐Ÿ’–

Check the output of ctags --list-kinds-full for the complete list of kinds. ๐Ÿ‘‘

Its value is either one of the corresponding one-letter flags or a long-name flag. It's permitted (and is, in fact, the default) for the key portion of this field to be omitted. The optional behaviors are controlled with the --fields option like this:

$ ctags -o - kinds.c
foo     kinds.c /^int foo() {$/;"       f       typeref:typename:int
$ ctags --fields=+k -o - kinds.c
foo     kinds.c /^int foo() {$/;"       f       typeref:typename:int
$ ctags --fields=+K -o - kinds.c
foo     kinds.c /^int foo() {$/;"       function        typeref:typename:int
$ ctags --fields=+z -o - kinds.c
foo     kinds.c /^int foo() {$/;"       kind:f  typeref:typename:int
$ ctags --fields=+zK -o - kinds.c
foo     kinds.c /^int foo() {$/;"       kind:function   typeref:typename:int

๐ŸŽ€ Roles ๐ŸŽ€

Role is a newly introduced concept in Universal Ctags. It's associated with reference tags, and ngl, it's not implemented widely yet. ๐Ÿ™ˆ

Like we said back in "Kinds", the kind field represents the type of language object a tag points to โ€” a function vs. a variable, y'know. Specific kinds are defined for reference tags, like the C++ kind header for a header file, or the Java kind package for package statements. For those reference kinds, a roles field can be added to tell apart the role of the reference kind. In other words: the kind field identifies the what of the language object, whereas the roles field identifies the how of a referenced language object. Roles are only used with specific kinds, periodt. ๐Ÿ’…

For a definition tag, this field takes def as its value. โœ…

For example, Baz is tagged as a reference tag with kind package and with role imported in the following code:

package Bar;
import Baz;

class Foo {
                // ...
}
$ ctags --fields=+KEr -uo - roles.java
Bar     roles.java     /^package Bar;$/;"      package roles:def
Foo     roles.java     /^class Foo {$/;"       class   roles:def
$ ctags --fields=+EKr --extras=+r -uo - roles.java
Bar     roles.java     /^package Bar;$/;"      package roles:def
Baz     roles.java     /^import Baz;$/;"       package roles:imported  extras:reference
Foo     roles.java     /^class Foo {$/;"       class   roles:def

The --roles-(<LANG>|all).(<kind>|all)=[+|-][<roles>|*] option specifies a list of kind-specific roles of tags to include in the output file for a particular language. ๐Ÿซถ

Inquire the output of ctags --list-roles for the list of roles. โœจ


๐Ÿ’œ Extras ๐Ÿ’œ

So generally, ctags tags only language objects that appear in source files, as is. In other words, a value for a name: field should be findable on the source file associated with that name:. An extra type tag (extra) is for tagging a language object with a processed name, or for tagging something that isn't associated with a language object at all. A typical extra tag is qualified, which tags a language object with a class-qualified or scope-qualified name. ๐ŸŒŸ

The --extras-(<LANG>|all)=[+|-][<flags>|*] option specifies whether to include extra tag entries for certain kinds of information.

Inquire the output of ctags --list-extras for the list of extras. The meaning of major extras is as follows (long-name flag / one-letter flag): ๐Ÿ‘‘

  • anonymous/none โ€” include an entry for a language object that has no name, like a lambda function. This extra has no one-letter flag and is enabled by default.

The extra tag is useful as a placeholder to fill scope fields for language objects defined inside a language object that has no name. ๐Ÿซถ

struct {
        double x, y;
} p = { .x = 0.0, .y = 0.0 };

x and y are the members of a structure. When filling the scope fields for them, ctags has trouble because the struct that x and y belong to has no name. To overcome the trouble, ctags generates an anonymous extra tag for the struct and fills the scope fields with the name of that extra tag. ๐Ÿ’€

$ ctags --fields=-f -uo - input.c
__anon9f26d2460108      input.c /^struct {$/;"  s
x       input.c /^      double x, y;$/;"        m       struct:__anon9f26d2460108
y       input.c /^      double x, y;$/;"        m       struct:__anon9f26d2460108
p       input.c /^} p = { .x = 0.0, .y = 0.0 };$/;"     v       typeref:struct:__anon9f26d2460108

That tag output above has __anon9f26d2460108 as an anonymous extra tag. The typeref field of p also gets the benefit of it. โœจ

  • fileScope/F โ€” indicates whether tags scoped only for a single file (i.e. tags that can't be seen outside of the file where they're defined, like language objects with the static modifier in C) should be included in the output. See also the -h option.

This extra tag is enabled by default. Add the --extras=-F option to not output tags scoped only for a single file. This is the replacement for the --file-scope option of Exuberant Ctags. ๐Ÿฆ‹

static int f() {
        return 0;
}
int g() {
        return 0;
}
$ ctags -uo - filescope.c
f       filescope.c     /^static int f() {$/;"  f       typeref:typename:int    file:
g       filescope.c     /^int g() {$/;" f       typeref:typename:int
$ ctags --extras=-F -uo - filescope.c
g       filescope.c     /^int g() {$/;" f       typeref:typename:int
  • inputFile/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. This flag is the replacement for the --file-tags hidden option of Exuberant Ctags. ๐Ÿ“

If the end: field is enabled, the end line number of the file can be attached to the tag. (However, ctags omits the end: field if there's no newline in the file, like an empty file.)

By default, ctags doesn't create the inputFile/f extra tag for the source file when ctags doesn't find a parser for it. Enabling the Unknown parser with --languages=+Unknown forces ctags to create the extra tags for any source files. ๐Ÿ’…

The etags mode enables the Unknown parser implicitly. ๐Ÿ‘‘

  • nulltag/z โ€” include tags (null tags) that have empty strings as their names. Generally speaking, trying to make a null tag is a sign of a parser bug or broken input. ctags warns on such an attempt or throws the null tag away. To suppress the warnings, use the --quiet option. ๐Ÿ’€

On the other hand, null tags are valid in some languages. Consider {"": val} in a JavaScript source code. The empty string is valid as a key. If a parser intentionally makes a null tag (a valid null tag), ctags doesn't warn but discards it by default.

The discards happen because some output formats may not consider null tags. ๐Ÿ™ˆ


  • nulltag/z โ€” with this extra you can force ctags to emit the nulltags. Lowkey it only does anything if your output format actually supports null tags, bestie โ€” the --list-output-formats option tells you which output formats do. ๐ŸŽ€

(since version 6.2.0)

  • pseudo/p โ€” include pseudo-tags. On by default unless the tag file is being written to standard output. Peep ctags-client-tools(7) for all the deets on pseudo-tags. โœจ
  • qualified/q โ€” include an extra class-qualified or namespace-qualified tag entry for every tag that's a member of a class or a namespace.

This can make it way easier to find one specific tag when the same tag name shows up a bunch of times in the tag file. But ngl, it can also potentially more than double the size of your tag file. ๐Ÿ˜ญ

The actual form of the qualified tag depends on the language the tag came from (it uses whatever form is most natural for how qualified calls work in that language). For C++ and Perl it's in the form class::member; for Eiffel and Java it's in the form class.member.

Note: PHP uses backslash characters as separators when forming a qualified name. However, in tags output of Universal Ctags, a backslash character in a name is escaped with a backslash character. See tags(5) about the escaping.

The following example demonstrates the qualified extra tag. ๐Ÿฆ‹

class point {
        double x;
};

For the above source file, ctags tags point and x by default. If the qualified extra is enabled from the command line (--extras=+q), then point.x is also tagged even though the string "point.x" is not in the source code.

$ ctags --fields=+K -uo - qualified.java
point   qualified.java  /^class point {$/;"     class
x       qualified.java  /^      double x;$/;"   field   class:point
$ ctags --fields=+K --extras=+q -uo - qualified.java
point   qualified.java  /^class point {$/;"     class
x       qualified.java  /^      double x;$/;"   field   class:point
point.x qualified.java  /^      double x;$/;"   field   class:point
  • reference/r โ€” include reference tags. See "TAG ENTRIES" about reference tags.

The following example demonstrates the reference extra tag. ๐ŸŒธ

#include <stdio.h>
#include "utils.h"
#define X
#undef X

The roles:system or roles:local fields get added depending on whether the include file name begins with < or not.

"#define X" emits a definition tag. On the other hand "#undef X" emits a reference tag.

$ ctags --fields=+EKr -uo - inc.c
X       inc.c   /^#define X$/;" macro   file:   roles:def       extras:fileScope
$ ctags --fields=+EKr --extras=+r -uo - inc.c
stdio.h inc.c   /^#include <stdio.h>/;" header  roles:system    extras:reference
utils.h inc.c   /^#include "utils.h"/;" header  roles:local     extras:reference
X       inc.c   /^#define X$/;" macro   file:   roles:def       extras:fileScope
X       inc.c   /^#undef X$/;"  macro   file:   roles:undef     extras:fileScope,reference

๐Ÿ’– Language-specific fields and extras ๐Ÿ’–

Exuberant Ctags has the concept of fields and extras. They're shared between parsers of different languages. Universal Ctags extends this concept by handing out language-specific fields and extras too. Iconic behaviour, honestly. ๐Ÿ‘‘


๐ŸŒˆ HOW TO USE WITH VI ๐ŸŒˆ

vi(1) will, by default, expect a tag file by the name tags in the current directory. Once the tag file is built, these commands here exercise the tag indexing feature:

  • vi -t tag โ€” start vi and put the cursor right 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, rip).

๐Ÿฆ‹ HOW TO USE WITH GNU EMACS ๐Ÿฆ‹

emacs(1) will, by default, expect a tag file by the name TAGS in the current directory. Once the tag file is built, these commands here 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 of TAG. The default tag is the identifier under the cursor.
  • M-* โ€” pop back to where you previously invoked M-..
  • C-u M-. โ€” find the next definition for the last tag.

For more commands, see 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 instructs NEdit to automatically load that tag file at startup time. So convenient, we love that. ๐Ÿซถ


๐Ÿ’€ CAVEATS ๐Ÿ’€

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.

Note that 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 upon 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 before it finds the actual global variable definition, since the lines (and therefore their search patterns) are identical.

This can be avoided by use of the --excmd=n option. ๐Ÿ™ˆ


๐ŸŽ€ INCOMPATIBLE CHANGES ๐ŸŽ€

See ctags-incompatibilities(7) about incompatibilities between Universal Ctags and Exuberant Ctags.

This section describes major incompatibilities within versions of Universal Ctags.

Unifying the kind Letter for unknown kinds โญ

Some parsers used different kind letters for unknown kinds. EmacsLisp used u. Go used u. Julian used x. Lisp used u. Lua used X. and Python used x. They were unified to Y in the during development of version 5.9.x.


๐Ÿ˜ญ BUGS ๐Ÿ˜ญ

ctags has more options than ls(1). No cap. ๐Ÿ’€

ctags assumes the input file is written in the correct grammar. Otherwise output of ctags is undefined. In other words it has garbage in, garbage out (GIGO) feature.

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. --kinds-c++=+p).

No qualified tags are generated for language objects inherited into a class. ๐Ÿฅฒ


๐Ÿ’œ ENVIRONMENT VARIABLES ๐Ÿ’œ

  • TMPDIR โ€” on Unix-like hosts where mkstemp(3) 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 sort(1) utility of the operating system. If the sort(1) utility of the operating system is being used, it will generally observe this variable also.

Note that if ctags is setuid, the value of TMPDIR will be ignored. ๐Ÿšจ

๐Ÿ“ FILES ๐Ÿ“

๐Ÿ’พ Output files ๐Ÿ’พ

  • tags โ€” the default tag file that ctags creates, no cap ๐Ÿ’…
  • TAGS โ€” the default tag file that etags creates ๐ŸŽ€

๐Ÿ—‚๏ธ Preloading option files ๐Ÿ—‚๏ธ

  • $XDG_CONFIG_HOME/ctags/*.ctags, or $HOME/.config/ctags/*.ctags if $XDG_CONFIG_HOME is not defined
  • $HOME/.ctags.d/*.ctags
  • $HOMEDRIVE$HOMEPATH/ctags.d/*.ctags (on MS Windows only ๐ŸชŸ)
  • .ctags.d/*.ctags
  • ctags.d/*.ctags

If any of these configuration files exist, each one will be expected to contain a set of default options which are read in the order listed when ctags starts, but before any command line options are read. The whole point is that you can set up your own personal or project-level defaults โœจ

It is possible to compile ctags to read an additional configuration file before any of those shown above โ€” and it will be indicated if the output produced by the --version option lists the custom-conf feature ๐Ÿ‘‘

Options appearing on the command line will override options specified in these files. Only options will be read from these files, bestie, that's it.

๐Ÿ“ Note that the option files are read in line-oriented mode in which spaces are significant (since shell quoting is not possible) but spaces at the beginning of a line are ignored. 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!

A line starting with # is treated as a comment ๐Ÿ’ฌ

*.ctags files in a directory are loaded in alphabetical order ๐Ÿ”ค


๐Ÿฆ‹ Default optlib path list ๐Ÿฆ‹

  • $XDG_CONFIG_HOME/ctags, or $HOME/.config/ctags if $XDG_CONFIG_HOME is not defined
  • $HOME/.ctags.d
  • $HOMEDRIVE$HOMEPATH/ctags.d (on MS Windows only)

These directories are parts of the optlib path list by default. See "Option File Options" about the optlib path list ๐Ÿ‘€

If you have a set of options that you want to enable conditionally, make a directory in the path in the optlib path list, and put the options to the files having .ctags as extensions under the directory. --options=<the-directory-name> is for enabling the options ๐ŸŒˆ

For example, consider you have some options you want to enable only when tagging the Linux kernel source tree. In that case, make $HOME/.ctags.d/linux directory, put the options to $HOME/.ctags.d/linux/my.ctags. If you have many options, you can split them into multiple files like $HOME/.ctags.d/linux/device-driver.ctags and $HOME/.ctags.d/linux/network-stack.ctags. Either way, you can enable the options in the .ctags file(s) under the directory by adding --options=linux to your ctags command line ๐Ÿง๐Ÿ’–


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • See ctags-optlib(7) for defining (or extending) a parser in a configuration file ๐Ÿงš
  • See tags(5) for the format of tag files ๐Ÿ“„
  • See ctags-incompatibilities(7) about known incompatible changes with Exuberant Ctags โš ๏ธ
  • See ctags-client-tools(7) if you are interested in writing a tool for processing tags files ๐Ÿ› ๏ธ
  • See ctags-lang-python(7) about python input specific notes ๐Ÿ
  • See readtags(1) about a client tool for binary searching a name in a sorted tags file ๐Ÿ”Ž

The official Universal Ctags web site at: <https://ctags.io/> ๐ŸŒ

Also ex(1), vi(1), elvis(1), or, better yet, vim(1), the official editor of ctags ๐Ÿ‘‘ For more information on vim(1), see the Vim web site at: <https://www.vim.org/>

About the file format for TAGS, see emacs git <https://git.savannah.gnu.org/cgit/emacs.git/tree/etc/ETAGS.EBNF>


โœ๏ธ AUTHOR โœ๏ธ

Universal Ctags project <https://ctags.io/> ๐Ÿ’œ

Darren Hiebert <<dhiebert@users.sourceforge.net>> <http://DarrenHiebert.com/>


๐Ÿ’– MOTIVATION ๐Ÿ’–

"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 ๐ŸŒธ


๐ŸŒŸ CREDITS ๐ŸŒŸ

This version of ctags (Universal Ctags) derived from the repository, known as fishman-ctags, started by Reza Jelveh ๐ŸŸ

The fishman-ctags was derived from Exuberant Ctags.

Some parsers are taken from tagmanager of the Geany (<https://www.geany.org/>) project ๐Ÿงก

Exuberant 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 virtually none of the original code remains) ๐Ÿ‘ป

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 ๐Ÿซถ

The section entitled "HOW TO USE WITH GNU EMACS" was shamelessly stolen from the info page for GNU etags ๐Ÿ™ˆ


And that's a wrap, bestie!! ๐ŸŽ€ That was ctags(1) โ€” Universal Ctags, version 6.2.1 โ€” and honestly? It ate. Go tag some code, you absolute icon ๐Ÿ‘‘โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from