ctags(1)
ctags(1) π β Universal Ctags
This is the ctags(1) page for Universal Ctags, bestie, and itβs lowkey iconic. π«Ά
πΈ NAME πΈ
ctags β Generate tag files for source code
β¨ SYNOPSIS β¨
ctags [<options>] [<source_file(s)>]
etags [<options>] [<source_file(s)>]
π¦ DESCRIPTION π¦
Okay so ctags and etags (see the -e option) β hereinafter collectively called ctags, except where theyβre distinguished β generate an index (or βtagβ) file for a whole variety of language objects found in source file(s). This tag file lets those 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. π
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. β¨
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. No cap.
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 byctags, 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-featuresoption, which will includewildcardsin 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
--recurseoption. To see the list of built-in exclude patterns, use--list-excludes. - See also the description for
--exclude-exception=option.
- 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
--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
ctagsto ignore all files underfoodirectory exceptfoo/main.c, use the following command line:--exclude=foo/* --exclude-exception=foo/main.c.
- For an example, you want
--filter[=(yes|no)]β Makesctagsbehave as a filter, reading source file names from standard input and printing their tags to standard output on a file-by-file basis. If--sortis 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. π--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 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.
- Note that if the file name read is a directory and
--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
-Loption, then the current directory (i.e.'.') is assumed. Symbolic links are followed by default (See--linksoption). If you donβt like these behaviors, either explicitly specify the files or pipe the output offind(1)intoctags -L -instead. See, also, the--excludeand--maxdepthto limit recursion. - Note: This option is not supported on all platforms at present. It is available if the output of the
--helpoption includes this option.
- If the list of supplied files is empty and no file list is specified with the
-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.
- If file is specified as
π‘ quick note bestie: that file we were just talking about? It gets read in line-oriented mode β meaning a new line is the only delimiter, and non-trailing white space counts as significant. Why? So you can actually pass in file names that have spaces in them π
(trailing white space does get stripped from lines, tho). Real talk: this can affect how options get parsed if you include them in the input. You've been warned π«Ά
--append[=(yes|no)]β tells ctags whether the tags it makes from your files should get appended to whatever's already in the tag file, or straight up replace it. Default isno, so no sneaky appending unless you ask. πΈ-aβ baby version of--append. Same energy, same job. β¨-f <tagfile>β pick the name for your tag file, bestie. Default is"tags", or"TAGS"if you're in etags mode. And if you set<tagfile>to-, the tags get written to standard output instead of a file. π
Okay so this next part is iconic protective behavior: ctags will stubbornly refuse to take orders if the tagfile already exists and its first line contains something other than a valid tags line. Why should you care? Because it saves your neck if you accidentally type ctags -f *.c β which would otherwise bulldoze your first C file with the tags generated by all the rest ππ. It also refuses a multi-character file name starting with a - (dash), because that almost always means you forgot the tag file name and this option tried to grab the next option as the file name. If you genuinely want your output tag file to be named -ugly, write it as -f ./-ugly. Periodt.
Also!! This option must appear before the first file name. And if you specify it more than once, only the last one applies. π«‘
-o <tagfile>β literally the same as-f tagfile. That's it. That's the whole bullet. π
β¨ Output Format Options β¨
--format=(1|2)β changes the format of the output tag file. Right now the only valid values for level are1or2. Level1is the original tag file format, level2is the new extended format with extension fields (but done in a way that keeps backward-compatibility with originalvi(1)implementations, slay). Default level is2. [Ignored in etags mode] π--output-format=(u-ctags|e-ctags|etags|xref|json)β sets the output format. Default isu-ctags. Wanna know aboutu-ctagsande-ctags? Seetags(5). For etags see-e, for xref see-x. Heads up: thejsonformat is only available if the ctags executable is built withlibjansson. More on json over atctags-client-tools(7). π¦-eβ same as--output-format=etags. Enables etags mode, which creates a tag file for use with the Emacs editor. Bonus lore: if ctags is invoked by a name containing the string"etags"(either by renaming the executable or making a link to it), etags mode gets enabled automatically. β¨-xβ same as--output-format=xref. 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 that defines the tag. No tag file is written, and all options affecting tag file output get ignored. π ββοΈ
Example applications for this feature, since I know you're gonna ask:
- generating a listing of all functions located in a source file β e.g.
ctags -x --kinds-c=f file - 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)β should the tag file be sorted on the tag name? Default isyes. Fun fact: originalvi(1)required sorted tags, so this is ancient lore. Thefoldcasevalue gives you case insensitive (a.k.a. case-folded) sorting. β οΈ But listen: fast binary searches of tag files sorted with case-folding will need special support from the tools using tag files β like what you get in the ctagsreadtagslibrary, or Vim version 6.2 or higher (using"set ignorecase"). [Ignored in etags mode] πΈ-uβ equivalent to--sort=no(i.e. "unsorted"). Chaos mode, respectfully. π--etags-include=<file>β includes a reference to<file>in the tag file. You can specify this option as many times as you want, bestie. It 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 your input files. If you set this, Universal Ctags converts the input from this encoding to the encoding specified by--output-encoding=encoding. Glow-up for your encodings. β¨--input-encoding-<LANG>=<encoding>β specifies a specific input<encoding>just for<LANG>. It overrides the global default value you gave with--input-encoding. Per-language treatment, we love to see it. π--output-encoding=<encoding>β specifies the<encoding>of the tags file. Universal Ctags converts the encoding of input files from whatever--input-encoding=<encoding>says to this encoding.
Also, <encoding> gets 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 files whose language it can't figure out (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 auto-selecting based on extension.
Plus! The special value auto means the language should be automatically selected β which effectively disables this option. π€·ββοΈ
--languages=[+|-](<list>|all)β specifies the languages for which tag generation is enabled.<list>holds a comma-separated list of language names (case-insensitive; either built-in or user-defined).
Okay here's the mechanics, pay attention bestie π: if the first language of <list> isn't preceded by either a '+' or '-', the current list (the current settings of enabled/disabled languages managed internally by ctags) gets cleared before adding or removing the languages in <list>. Until a '-' is encountered, each language in <list> gets added to the current list.
As either the '+' or '-' is encountered in <list>, the languages following it get added or removed from the current list, respectively. So it's super simple to replace the current list with a new one, or add/remove languages from it. π
The actual list of files for which tags get generated depends on the language extension mapping in effect (see the --langmap option). Note that most languages, including user-defined ones, are enabled unless you explicitly disable them with this option. Language names in the list can be any built-in language or one previously defined with --langdef. π
The default is all, which is also accepted as a valid argument. Wanna see a list of all (built-in and user-defined) language names? Check --list-languages. β
Also note: --languages= works cumulatively β the option can be specified with different arguments multiple times on one 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 the "Determining file language" stage. π΅οΈββοΈ
The parameter <pattern> is not a list. Use this option multiple times on a command line to add or remove multiple alias patterns.
Wanna restore the default language aliases? Just specify default. π«
Using all for <LANG> actually means something, in these two cases:
--alias-all=β clears the aliases setting of all languages.--alias-all=defaultβ restores the default language aliases for all languages.
--guess-language-eagerlyβ looks into the file contents to heuristically guess the proper language parser. See "Determining file language". Main character detective energy π-Gβ equivalent to--guess-language-eagerly. Short and sweet. π--langmap=<map>[,<map>[...]]β controls how file names get mapped to languages (see--list-maps). Each comma-separated<map>is made of the language name (built-in or user-defined), a colon, and a list of file extensions and/or file name patterns. A file extension is written by putting a period before it (e.g..c). A file name pattern goes in parentheses (e.g.([Mm]akefile)). πΈ
If your C compiler's runtime library supports it, the file name pattern can contain the usual shell wildcards common on Unix β and be sure to quote the option parameter so the shell doesn't expand the wildcards before ctags ever sees them!! π€ You can check whether shell wildcards are available on your platform by looking at the output of --list-features; if wildcards shows up in the compiled feature list, you're good. Otherwise, file name patterns get matched against file names using a simple textual comparison.
When you map a file extension with --langmap, it first gets unmapped from any other languages. (The --map-<LANG> option gives you more fine-grained control.) π
If the first character in a <map> is a plus sign ('+'), the extensions and file name patterns in that map get appended to the current map for that language; otherwise the map replaces the current map. For example:
- to say only files with extensions of
.cand.xcount as C language files:--langmap=c:.c.x - to also add files with extension
.jas Java language files:--langmap=c:.c.x,java:+.j - to map makefiles (files named
Makefile,makefile, or having the extension.mak) to a language called make:--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.) π
--langmap=fortran:β that's the way to yeet a language's mapping entirely, which also means ctags justβ¦ won't auto-generate tags for that language anymore. Specify an empty extension list like that, ok?- To put the default mappings back for one specific language, hand it the keyword
default. To restore defaults for every language at once, just say--langmap=default. iconic, honestly. π
Heads up bestie: when ctags is figuring out what language a file is, it tests file name patterns before file extensions. This order is a Universal Ctags thing and it's different from Exuberant Ctags. The whole ~lore~ behind this incompatible change lives in ctags-incompatibilities(7). iykyk. π
--map-<LANG>=[+|-]<extension>|<pattern>β this is the β¨fine-grainedβ¨ way to control which file names map to which languages, way more surgical than--langmap.
So like, in ctags, more than one language can map to the same file name <pattern> or file <extension> β that's an N:1 map, and it's totally valid. --langmap, by contrast, only handles a 1:1 map: one language, one <pattern>/<extension>, no sharing. The classic N:1 example? C++ and ObjectiveC β both of them map to .h as a file extension. not a drill. π¦
- A file extension gets a period in front of it, like
.c. - A file name pattern goes inside parentheses, like
([Mm]akefile). - Prefix with plus (
+) to add, minus (-) to remove. No prefix at all = replacing the map of<LANG>.
Unlike--langmap,<extension>(or<pattern>) here is not a list.--map-<LANG>takes exactly one extension or pattern per go. But bestie you can absolutely drop the option multiple times on the same command line with different arguments. π
π Tags File Contents Options π
Peep the "TAG ENTRIES" section if you wanna know about fields, kinds, roles, and extras. π
--excmd=(number|pattern|mix|combine)β decides what flavour of EX command ctags uses to locate tags in the source file. [Ignored in etags mode, fyi]
The valid values for type are, and yes, you can give either the whole word or just the first letter:
numberβ use only line numbers in the tag file to locate tags. This has four glow-up advantages:- Significantly reduces the size of the resulting tag file. tiny king. π
- Eliminates failures to find tags because the line defining the tag changed and the pattern match flops. (Note: some editors, like
vim, can recover in many of these situations. slay.) - Eliminates finding identical matching, but incorrect, source lines β see "BUGS".
- Retains separate entries in the tag file for lines that are identical in content. In pattern mode, duplicates get dropped because the search patterns they generate are identical, making duplicate entries useless anyway.
However β and this is the one big drawback, don't say I didn't warn you π β changes to the source files can make the line numbers recorded in the tag file stop matching the lines in the source file, so jumps to some tags miss the target definition by one or more lines. Basically, this option is best when the source code it's applied to isn't subject to change. Selecting this type causes the following options to be ignored: -B, -F.
Also:numbertype is ignored in Xref and JSON output formats. Use--_xformat="...%n"for Xref output format, or--fields=+n-Pfor JSON output format. π
patternβ use only search patterns for all tags, rather than the line numbers usually used for macro definitions. The advantage? No referencing obsolete line numbers when lines have been added or removed since the tag file was generated. a vibe. β¨mixedβ in this mode, patterns are generally used, with exceptions. For Fortran, line numbers are used for common blocks because their corresponding source lines are generally identical, which makes pattern searches useless for finding all matches.
Exuberant Ctags has one more exception: for C, line numbers are used for macro definition tags. Universal Ctags does not 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. the original main character, honestly. π«Ά
combineβ concatenate the line number and pattern with a semicolon in between.
-nβ equivalent to--excmd=number. simple as. π-Nβ equivalent to--excmd=pattern.--extras=[+|-][<flags>|*]β says whether to include extra tag entries for certain kinds of information. Wanna know what counts as an extra? Check the "Extras" subsection. π¦
The parameter <flags> is a set of one-letter flags (and/or long-name flags), each one representing a kind of extra tag entry to include in the tag file.
- Flag preceded by
+or-? That flag's effect gets added to, or removed from, whatever's currently enabled. - No sign at all? The flags replace any current settings.
*given? All entries are included. periodt. β¨
This --extras= option is for the extras that are common across all languages (the language-independent ones). Universal Ctags also supports language-specific extras β see "Language-specific fields and extras" for the concept. For those, use the --extras-<LANG>= option.
--extras-(<LANG>|all)=[+|-][<flags>|*]β same deal but for one specific language<LANG>, controlling whether to include extra tag entries for certain kinds of information for that language. Universal Ctags is the one that introduced language-specific extras, so check "Language-specific fields and extras" for the concept. this option is literally for controlling them. π- Give
allas<LANG>to apply<flags>to every language. - All extras get enabled by giving
'*'as the<flags>parameter. - Give nothing as
<flags>(--extras-all=) and all extras are disabled. - Those last two combos are super useful for testing. π§
- Give
Wanna see the extras for a specific <LANG>? Check the output of the --list-extras=<LANG> option.
--fields=[+|-][<flags>|*]β specifies which language-independent fields go into the tag entries. Language-independent fields are extension fields common to all languages. The "TAG FILE FORMAT" section and the "Extension fields" subsection have all the deets on extension fields. π
The parameter <flags> is a set of one-letter or long-name flags, each representing one type of extension field to include. Every flag or group of flags may be preceded by + to add it to the default set, or - to exclude it.
No preceding + or - anywhere? Then only the fields explicitly listed in <flags> get included in the output (i.e. you're overriding the default set, bestie). All fields are included if '*' is given. β
This option is ignored if --format=1 (the legacy tag file format) has been specified. π
Use the --fields-<LANG>= option for the language-specific fields, obviously.
--fields-(<LANG>|all)=[+|-][<flags>|*]β specifies which language-specific fields go into the tag entries. Universal Ctags supports language-specific fields β see "Language-specific fields and extras" for the concept. πΈallas<LANG>= apply<flags>to every language.'*'as<flags>= all fields enabled.- Nothing as
<flags>(i.e.--fields-all=) = all fields disabled. - Those two combos? Testing gold. π
For what <flags> even means, see the description of --fields=[+|-][<flags>|*]. And use --fields= for the language-independent fields.
--kinds-(<LANG>|all)=[+|-](<kinds>|*)β hands you a list of language-specific<kinds>of tags to include in the output file for a particular language.<LANG>is case-insensitive and has to be one of the built-in language names β run--list-languagesfor the full list, iykyk. π
The parameter <kinds> is a group of one-letter or long-name flags designating kinds of tags (particular to the language) to include or exclude from the output. The specific sets of flags recognized per language, their meanings and their defaults? --list-kinds-full will show you all of it. π
- Each letter or group of letters may be preceded by
+to add it to the default set, or-to remove it from it. - No preceding
+or-sign? Then only the kinds explicitly listed get included in the output β i.e. you're overriding the default for that language. π - Give
'*'as the parameter to include all kinds implemented in<LANG>. - Give
allas<LANG>and the<kinds>parameter affects all languages defined in ctags. Givingallonly makes sense when'*'orFis given as the<kinds>parameter, tho.
Example time, C language: 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++ are synchronized: enabling (or disabling) a kind in one language enables the kind with the same one-letter and long-name in the other. See the description of the MASTER column of --list-kinds-full. π¦
--pattern-length-limit=<N>β truncates patterns of tag entries after<N>characters. Disable it by setting it to0(default is96). βοΈ
Why would you want this? An input source file with long lines and multiple tag matches per line can generate an excessively huge tags file if the pattern length is unconstrained. Case in point: running ctags on a minified JavaScript source file often exhibits exactly this behavior. not fun. π
...and honestly? That truncation logic is lowkey doing the most for you π«Ά It refuses to cut in the middle of a UTF-8 code point that spans multiple bytes, because that would mean writing invalid byte sequences out of perfectly valid input files. Iconic behaviour, tbh.
Now, because of that, you can end up with an extra 3 bytes above the limit you configured in the worst case β specifically when a 4 byte code point starts right before the limit. So set your limits accordingly, bestie. π
Also, real talk: this handling is fairly naive and fast. It's resistant against any input, sure, but it needs a valid input to work properly β it is not guaranteed to do what you expect when you feed it partially invalid UTF-8. And it partially affects non-UTF-8 input too, if the byte sequence sitting at the truncation length happens to look like a multibyte UTF-8 sequence. That should be rare tho, and worst case you get up to an extra 3 bytes above the limit. No cap.
--pseudo-tags=[+|-](<pseudo-tag>|*)β turns emitting a pseudo-tag named <pseudo-tag> on or off. Pass'*'and it enables/disables emitting all the pseudo-tags at once β¨--put-field-prefixβ slapsUCTAGSin front of the names of fields that are newly introduced in Universal Ctags π
So here's the tea: some fields are new in Universal Ctags, and more are coming in the future. Other tag generators might also introduce their own specific fields.
Which means there's a whole concern about field names colliding β mixing tag files generated by multiple tag generators (Universal Ctags included) gets messy. This option is the workaround for such a situation π
$ 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 example above, the prefix gets put on the end field, which is the one newly introduced in Universal Ctags. See? It's giving attention to detail π
--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> says which kind the <roles> are defined in. <LANG> says which language the kind is defined in. Every role in <roles> has to be wrapped in braces (like {system} for a role literally named "system").
Just like the --kinds-<LANG> option: + adds the role to the list, - removes it from the list, and * means include all roles of that kind. Give the option no argument at all and the list becomes empty. Periodt.
You can name a kind with either a one-letter flag or a long name flag surrounded by braces β both are acceptable (e.g. --roles-C.h=+{system}{local} or --roles-C.{header}=+{system}{local}). '*' can be used for <KIND> only when you're adding/removing all roles of all kinds in a language to/from the list (e.g. --roles-C.*=* or --roles-C.*=).
And all can be used for <LANG> only when you're adding/removing all roles of all kinds in all languages to/from the list (e.g. --roles-all.*=* or --roles-all.*=). Very main character energy π
--tag-relative=(yes|no|always|never)β controls how the file paths recorded in the tag file look π¦
Default is yes when running in etags mode (that's the -e option, iykyk), and no otherwise.
yesβ 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 were given with absolute paths.noβ the file paths recorded in the tag file should be relative to the current directory, unless the files supplied on the command line were given with absolute paths.alwaysβ the recorded file paths should be relative even if the source file names were passed in with absolute paths.neverβ the recorded file paths should be absolute even if the source file names were passed in with relative paths. Flip it completely π
--use-slash-as-filename-separator[=(yes|no)]β uses the slash ('/') character as the filename separator instead of the backslash ('\') character when printing theinput:field π
Default is yes for the default "u-ctags" output format, and no for every other format.
Heads up: this option is available on MS Windows only. Sorry bestie π«Ά
-Bβ use backward searching patterns (like?pattern?). [Ignored in etags mode] π-Fβ use forward searching patterns (like/pattern/). This is the default. [Ignored in etags mode] β¨
π Option File Options π
--options=<pathname>β read additional options from a file or a directory π
ctags searches for <pathname> in the optlib path list first. If it can't find a file or directory in that list, it reads the file or directory at the <pathname> you specified.
If you hand it a file, that file should contain one option per line. If you hand it a directory, the files under it suffixed with .ctags get read in alphabetical order. Cute and orderly π
Special case alert: if --options=NONE is specified as the first option on the command line, preloading is disabled β that option will disable the automatic reading of any configuration options from a file (peep "FILES").
--options-maybe=<pathname>β same as--options, but it doesn't throw an error if the file (or directory) specified with <pathname> doesn't exist. Chill vibes only π¦--optlib-dir=[+]<directory>β adds an optlib <directory> to the optlib path list, or resets that list. Check"Default optlib path list"for what the default elements are πΈ
π§ optlib Options π§
See ctags-optlib(7) for the deets on each option. Go read it, bestie, it's literally right there π
--kinddef-<LANG>=<letter>,<name>,<description>β defines a kind for <LANG>. Don't get it confused with--kinds-<LANG>β they are not the same thing, ok? π--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>]β defines a multi-line regular expression for locating tags in a specific language π--regex-<LANG>=/<line_pattern>/<name_pattern>/<kind-spec>/[<flags>]β defines a single-line regular expression for locating tags in a specific language β¨
π Language Specific Options π
--if0[=(yes|no)]β your preference on whether code inside an"#if 0"branch of a preprocessor conditional should be examined for non-macro tags (macro tags are always included, no debate) π«Ά
Because the whole point of that construct is to disable code, the default value is no (disabled).
Okay but listen: this is a preference, not a promise. It does not guarantee that code inside an "#if 0" branch gets skipped, because the fall-back algorithm used to generate tags when preprocessor conditionals are too complex follows all branches of a conditional. It's doing its best π
--line-directives[=(yes|no)]β specifies whether#linedirectives should be recognized π
These show up in the output of a preprocessor and contain the line number, and possibly the file name, of the original source file(s) that the preprocessor output file was generated from. This option is off by default.
When you turn it on, ctags will 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's assumed the original source files live relative to the preprocessor output file (unless, of course, the #line directive specifies an absolute path β then it does what it says).
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 isn't known toctags. Just so you know π
-D <macro>=<definition>β defines a C preprocessor <macro>. This emulates the behaviour of the correspondinggccoption π
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. It's giving overachiever, and we love that π
-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 is interpreted β i.e. whether or not they're considered globally visible, or visible only within the file they're defined in. It does not map the extension to any particular language, ok? Don't come for me. Any tag located in a non-include file that can't be seen (e.g. linked to) from another file is considered to have file-limited (e.g. static) scope. No kind of tag appearing in an include file will be considered to have file-limited scope. Periodt.
If the first character in the list is '+', the extensions in the list get appended to the current list; otherwise the list replaces the current list. Also peep the fileScope/F flag of the --extras option β¨
The default list is .h.H.hh.hpp.hxx.h++.inc.def. To restore the default list, specify "-h default".
Note: if an extension you pass to this option isn't already mapped to a particular language (see"Determining file language", above), you'll also need to use either the--map-<LANG>,--langmapor--language-forceoption. Otherwise it's just sitting there unmapped, and that's awkward π
-I <identifier-list>β specifies an <identifier-list> of identifiers that are to be specially handled while parsing C and C++ source files πΈ
This option is specifically provided to handle the special cases that come up from using preprocessor macros. When the identifiers listed are simple identifiers, these identifiers will be ignored during parsing of the source files.
- If an identifier ends with a
+character (like-I FOO+), ctags will also ignore any parenthesis-enclosed argument list that happens to come right after that identifier in the source files. There's a whole example of-I MODULE_VERSION+below, don't worry π- If two identifiers are separated by the
=character (like-I FOO=BAR), then the first identifier gets replaced by the second identifier for parsing purposes. This list of identifiers can come straight from the command line or be read in from a separate file. Peep the-I CLASS=classexample below β¨ - If the very first character of <identifier-list> is
@,., or a pathname separator (/or\), or if the first two characters specify a drive letter (e.g.C:), then the <identifier-list> parameter gets read as a filename β ctags opens it and reads a list of identifiers from it, one per input line π - Otherwise, <identifier-list> is just a list of identifiers (or identifier pairs) to be specially handled, each one delimited by either a comma or white space. Pro tip: if you're using white space, quote the whole thing so the list stays as one single command line argument, k? π«Ά
- You can supply multiple
-Ioptions, no cap. And to clear the list of ignore identifiers, just hand it a single dash (-) for <identifier-list> π§Ή
- If two identifiers are separated by the
So this feature is chef's kiss when preprocessor macros are used in a way that causes syntactic confusion just by existing. Honestly it's the best way of working around a bunch of problems caused by syntax-busting macros hanging out in source files (check "CAVEATS" β yes, ominous, iykyk π). Some examples will make this whole thing click:
int foo ARGDECL4(void *, ptr, long int, nbytes)
In the example above, the macro ARGDECL4 would get mistakenly interpreted 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$")
In this one, 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 whole 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 tries to complete the definition. Specifying -I MODULE_VERSION+ avoids that whole situation β¨
CLASS Example {
// your content here
};
The example above uses CLASS as a preprocessor macro which expands to something different on each platform. Like, CLASS may be defined as class __declspec(dllexport) on Win32 platforms and just plain class on UNIX. Normally, the absence of the C++ keyword class would cause the source file to be parsed incorrectly. Correct behavior can be restored by specifying -I CLASS=class. Periodt π
--param-<LANG>.<name>=<argument>β Set a<LANG>specific parameter, aka a parameter that's specific to that<LANG>.
You can list all the available parameters with --list-params π
π Listing Options π
--list-aliases[=(<language>|all)]β Lists the aliases for either the specified<language>or all languages, and then dips out (exits).allis the default value if you omit the option argument. These aliases are used when ctags is heuristically testing a language parser for a source file π¦--list-excludesβ Lists the current exclusion patterns used to exclude files. Simple as that, bestie π--list-extras[=(<language>|NONE|all)]β Lists the extras recognized for either the specified<language>or all languages. IfNONEis specified, it lists only extras common in all languages. See the "Extras" subsection to know what extras even are.allis the default value if the option argument is omitted.
An extra can be enabled or disabled 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 for specifying an extra.
The meaning of the columns in the output are as follows:
LETTERβ One-letter flag.-means the extra doesn't have a one-letter flag.NAMEβ Long-name flag. The long-name is used in the extras field.ENABLEDβ Whether the extra is enabled or not. Takesyesorno.LANGUAGEβ The name of the language if the extra is owned by a parser.NONEmeans the extra is common in parsers.DESCRIPTIONβ Human readable description for the extra.
--list-featuresβ Lists the compiled features. That's it, that's the whole vibe check β--list-fields[=(<language>|NONE|all)]β Lists the fields recognized for either the specified<language>or all languages. IfNONEis specified, it lists only fields common in all languages. See the "Extension fields" subsection to know what fields are.allis the default value if the option argument is omitted.
The meaning of the columns are as follows:
LETTERβ One-letter flag.-means the field doesn't have a one-letter flag.NAMEβ Long-name of the field.ENABLEDβ Whether the field is enabled or not. Takesyesorno.LANGUAGEβ The name of the language if the field is owned by a parser.NONEmeans the field is a language-independent field which is common in all languages.JSTYPEβ JSON type used in printing the value of the field when--output-format=jsonis specified. Seectags-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 allows disabling any fields π
OPβ How this field can be accessed from optscript code. This field is for Universal Ctags developers πDESCRIPTIONβ Human readable description for the field.
--list-kinds[=(<language>|all)]β A subset of--list-kinds-full. This option is kept for backward-compatibility with Exuberant Ctags π«Ά
This option prints only the LETTER, DESCRIPTION, and ENABLED fields of --list-kinds-full output. However, 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 names to be important π
This option does not work with --machinable nor --with-list-header. Noted π«
--list-kinds-full[=(<language>|all)]β Lists the tag kinds recognized for either the specified<language>or all languages, and then exits. See the "Kinds" subsection to learn what kinds are.allis 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 use of the --kinds-<LANG> option.
The meaning of the columns are as follows:
LANGUAGEβ The name of the language having the kind.LETTERβ 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 enabling theKfield 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. Takesyesorno.REFONLYβ Whether the kind is specialized for reference tagging or not. If the column isyes, the kind is for reference tagging, and it's 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 is 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 having the same long-name flag as 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 can see the ENABLED field of the local kind of the C++ language is changed even though the local kind of the C language is what's being enabled/disabled. If you swap the languages, you see the same result π
DESCRIPTIONβ Human readable description for the kind.
--list-languagesβ prints out the names of every language ctags knows about, then dips β¨ these language names are case insensitive and you can drop them into a bunch of other options like--language-force,--languages,--kinds-<LANG>,--regex-<LANG>, and friends.
If a language shows up with [disabled] after it, that parser is off π€ β to actually use it, pass the language as an argument to the --languages=+ option. okay bestie write that down π
Heads up:--machinableand--with-list-headerget straight-up ignored if you pair them with this option. no cap.
--list-map-extensions[=(<language>|all)]β lists the file extensions that link a file name to a language, for either the<language>you asked for or literally all of them, then exits. If you leave the option argument off,allis the default value π¦--list-map-patterns[=(<language>|all)]β same vibe but for the file name patterns that associate a file name with a language, for your<language>or all languages, and then it bounces.allis the default value if the option argument is omitted π--list-maps[=(<language>|all)]β the combo platter π lists both the file name patterns and the file extensions that associate a file name with a language, for the specified<language>or for all languages, and then exits.allis the default value if the option argument is omitted.
Wanna peek at extensions or patterns on their own? use --list-map-extensions or --list-map-patterns instead. Also go read the --langmap option and "Determining file language", above π
Fr fr: this option does not work with--machinablenor--with-list-header. don't try it.
--list-mline-regex-flagsβ outputs the list of flags you can use in a multiline regex parser definition. seectags-optlib(7)π§--list-params[=(<language>|all)]β lists the parameters for either the<language>you named or all languages, then exits.allis the default value when the option argument is omitted β¨--list-pseudo-tagsβ outputs the list of pseudo-tags π--list-regex-flagsβ lists the flags that are usable in the--regex-<LANG>option. seectags-optlib(7)πΈ--list-roles[=(<language>|all)[.(<kind-specs>|*)]]β lists the roles for either the specified<language>or all languages. If the option argument is omitted,allis the default value π
And if you tack on the <kindspecs> parameter after <language> (or all) joined with a ., it lists only the roles defined in those kinds. Both one-letter flags and long name flags wrapped in braces are acceptable as the <kindspecs> parameter π
What the columns mean, bestie:
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 itself.ENABLEDβ whether the kind is enabled or not. it takesyesorno.DESCRIPTIONβ 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, then exits.allis the default value if the option argument is omitted π--machinable[=(yes|no)]β uses the tab character as the separator for--list-option output. super handy for scripting π₯οΈ See "List options" for the 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 a detailed usage description to standard output, and then exits. your emotional support flag π«Ά-?β equivalent to--help.--help-fullβ prints a detailed usage description to standard output including experimental features, then exits. Visithttps://docs.ctags.io/for the info about the latest exciting experimental features π₯--licenseβ prints a summary of the software license to standard output, and then exits. legally iconic π--print-languageβ just prints the language parsers for the specified source files, and then exits π--quiet[=(yes|no)]β writes fewer messages (default isno) π€«--totals[=(yes|no|extra)]β prints statistics about the source files read and the tag file written during the current invocation of ctags. This option isnoby 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 ctags considers π Normally ctags doesn't read command line arguments until after options are read from the configuration files (see "FILES", below). But if this option is the first argument on the command line, it takes effect before any options are read from these sources. The default isno.-Vβ equivalent to--verbose.--version[=<language>|NONE]β prints a version identifier for ctags to standard output, then exits. Guaranteed to always contain the string"Universal Ctags"β See also the description forTAG_PROGRAM_VERSIONandTAG_OUTPUT_VERSIONinctags-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 ones are kept around for backward-compatibility with Exuberant Ctags β they're giving legacy energy, but they're still here π°οΈ
-wβ this option is silently ignored for backward-compatibility with the ctags of SVR4 Unix. literally does nothing, slay π--file-scope[=(yes|no)]β this option is removed. use--extras=[+|-]For--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 whole vibe of how ctags actually moves through your files, bestie. As ctags considers each source file name in turn, it tries to determine 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. Not us though β weβre not doing that whole βformat your code exactly like this or perishβ thing. π
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. Clean, sorted, iconic. β¨
πΊοΈ 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. Detective mode: activated. π
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. Itβs giving βwe only pull up to the party if youβre actually on the list.β π
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
.inextension, ctags applies the mapping to the file name without the extension. For example,config.his tested for a file namedconfig.h.in. Cute little name trickery. π - 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
#compdefor#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
TYPEas a name of interpreter and applies the same rule of"interpreter"heuristic testing if the first or last5lines 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:
<tag_name>: tag name<TAB>: single tab character<file_name>: name of the file in which the object associated with the tag is located<TAB>: single tab character<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).;"<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. Slay, backwards compatibility. π
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 as 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. Itβs giving secret handshake. π€«
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. Main character energy for real. π
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.
...and these extension fields are just tab-separated key-value pairs chilling at the end of the EX command as a comment, exactly like we said up above π
they show up in the general form key:value.
Also, you might get info about the scope of the tag definition β where the key bit equals some language-dependent construct name, and the value is the name declared for that construct in the program. That scope entry tells you where the tag was found, iykyk. Like, a tag made for a C structure member would have a scope looking like struct:myStruct π
The --fields=[+|-][<flags>|*] and --fields-(<LANG>|all)=[+|-][<flags>|*] options are the ones that decide which available extension fields get included in the tag entries, bestie.
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. The meaning of the major fields is as follows (long-name flag/one-letter flag):
access/aβ Indicates the visibility of this class member, where the value is specific to the language πend/eβ Indicates the line number of the end lines of the language object.extras/Eβ Extra tag type information. See "Extras" for the tea βfile/fβ Indicates that the tag has file-limited visibility. This key has no corresponding value. Enabled by default β¨implementation/mβ When present, this indicates 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 from which this class is derived (i.e. inherits from) π§¬input/Fβ The name of the source file wherenameis defined or referenced.kβ Kind of tag as one-letter. Enabled by default. This field has no long-name. See alsokind/zflag.Kβ Kind of tag as long-name. This field has no long-name. See alsokind/zflag.kind/zβ Include thekind:key in the kind field. See alsokandKflags.language/lβ Language of the source file containing the tag.line/nβ The line number wherenameis defined or referenced ininput.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 thenameininput.roles/rβ Roles assigned to the tag. See "Roles" for more details πsβ Scope of tag definition. Enabled by default. This field has no long-name. See alsoscope/Zflag.scope/Zβ Prepend thescope:key to the scope (s) field. See alsosflag.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 callable like function as atyperef:field. Enabled by default π
β¨ Kinds β¨
kind is the field that represents the kind of language object a tag is pointing at, and honestly the kinds used and defined are so different between parsers. Like, C language defines macro, function, variable, typedef, etc. β every parser's got its own vibe π
The --kinds-(<LANG>|all)=[+|-](<kinds>|*) option specifies a list of language-specific kinds of tags (or kinds, same thing) to include in the output file for a particular language.
Check the output of ctags --list-kinds-full for the complete list of the kinds, bestie.
Its value is either one of the corresponding one-letter flags or a long-name flag. It is 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 as follows π
$ 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, okay? It's a concept associated with reference tags, and ngl it is not implemented widely yet β so don't come for me if your fave language isn't on board π«Ά
Like we said earlier in "Kinds", the kind field represents the type of language object specified with a tag β think function vs. variable. Specific kinds are defined for reference tags, such as the C++ kind header for header file, or the Java kind package for package statements. For such reference kinds, a roles field can be added to distinguish 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 π
For a definition tag, this field takes def as a value.
For example, Baz is tagged as a reference tag with kind package and with role imported with 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, bestie π
πΈ Extras πΈ
So generally, ctags tags only language objects appearing in source files, as is. In other words, a value for a name: field should be found on the source file associated with the name:. An extra type tag (extra) is for tagging a language object with a processed name, or for tagging something not associated with a language object. 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 the 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 in a language object with 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 where x and y belong to has no name. For overcoming the trouble, ctags generates an anonymous extra tag for the struct and fills the scope fields with the name of the 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
The above tag output has __anon9f26d2460108 as an anonymous extra tag. The typeref field of p also receives the benefit of it π«Ά
fileScope/Fβ 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 language objects withstaticmodifier of C language) should be included in the output. See also the-hoption.
This extra tag is enabled by default. Add --extras=-F option not to output tags scoped only for a single-file. This is the replacement for --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--file-tagshidden 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 no newline is 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 Unknown parser with --languages=+Unknown forces ctags to create the extra tags for any source files.
The etags mode enables the Unknown parser implicitly. β
pseudo/pβ Include pseudo-tags. Enabled by default unless the tag file is written to standard output. Seectags-client-tools(7)about the detail of pseudo-tags.qualified/qβ Include an extra class-qualified or namespace-qualified tag entry for each tag which is a member of a class or a namespace. π
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. π
The actual form of the qualified tag depends on the language the tag came from, using whatever form feels most natural for qualified calls 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: in PHP, qualified names are formed using backslash characters as separators. However, in the 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 will be 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 are common between parsers of different languages. Universal Ctags extends this concept by providing language-specific fields and extras.
πΈ 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, the following commands exercise the tag indexing feature:
vi -t tagβ start vi and position the cursor at the file and line where tag is defined.:ta tagβ find a tag.- Ctrl+] β find the tag under the cursor.
- Ctrl+T β return to the previous location before the jump to the tag (not widely implemented).
π¦ 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, the following commands 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 invokedM-..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.
π 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. Although 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 is 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 is 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).
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 wheremkstemp(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 created byctags.TAGSβ the default tag file created byetags.
Preloading option files
$XDG_CONFIG_HOME/ctags/*.ctags, or$HOME/.config/ctags/*.ctagsif$XDG_CONFIG_HOMEis not defined (on other than MS Windows)$HOME/.ctags.d/*.ctags$HOMEDRIVE$HOMEPATH/ctags.d/*.ctags(on MS Windows only).ctags.d/*.ctagsctags.d/*.ctags
If any of these configuration files exist, each 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. This makes it possible to set up personal or project-level defaults.
It is 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 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) 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/ctagsif$XDG_CONFIG_HOMEis not defined (on other than MS Windows)$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 π
okay bestie, when you're done here and you're like "wait, what else", the ctags cinematic universe is literally huge, so here's the map:
ctags-optlib(7)β read this for defining (or extending) a parser in a configuration file β¨tags(5)β this is the one that explains the format of tag files, iykyk πctags-incompatibilities(7)β everything about the known incompatible changes with Exuberant Ctags (yes, there ARE some, go look π)ctags-client-tools(7)β if you're interested in writing a tool for processing tags files, this is your moment, main character energy π«Άctags-lang-python(7)β about python input specific notes πreadtags(1)β about a client tool for binary searching a name in a sorted tags file, which is honestly so satisfying- The official Universal Ctags web site at:
https://ctags.io/π
Also give these a look: 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/
π AUTHOR π
- Universal Ctags project
https://ctags.io/ - Darren Hiebert
<dhiebert@users.sourceforge.net>βhttp://DarrenHiebert.com/
πΈ MOTIVATION πΈ
ngl this section is so sweet, I can't:
"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
likeβ¦ periodt. icons only π
β¨ CREDITS β¨
This version of ctags (Universal Ctags) derived from the repository, known as fishman-ctags, started by Reza Jelveh. slay.
The fishman-ctags was derived from Exuberant Ctags.
Some parsers are taken from tagmanager of the Geany (β https://www.geany.org/) project. we love a collab π«Ά
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). history!!
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. genuinely iconic, no cap ππ
The section entitled "HOW TO USE WITH GNU EMACS" was shamelessly stolen from the info page for GNU etags. (we respect the honesty π)
okay that's the whole page bestie, you made it to the end π this was Universal Ctags version 6.0.0, served fresh in the ctags(1) manual page, and yes β it's giving reference doc but make it cute. go tag something, go touch grass, ily π¦ππ
π¦ where this page comes from
- opensuse-leap 16.0: universal-ctags 6.0.0-bp160.1.12 Β· GPL-2.0-only
- opensuse-leap 16.0: universal-ctags 6.0.0-bp160.1.12 Β· GPL-2.0-only
- opensuse-leap 16.0: universal-ctags 6.0.0-bp160.1.12 Β· GPL-2.0-only
- opensuse-leap 16.0: universal-ctags 6.0.0-bp160.1.12 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms