# Ctags

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Ctags
> Markdown URL: https://mediated.wiki/source/Ctags.md
> Source: https://en.wikipedia.org/wiki/Ctags
> Source revision: 1336334795
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

**ctags** is a [shell](/source/Shell_(computing)) [command](/source/Command_(computing)) that generates an [index](/source/Index_(publishing)) (tag) file of programmatic [identifiers](/source/Identifier) parsed from [source code](/source/Source_code) [files](/source/File_(computing)) of various [programming languages](/source/Programming_language) to aid with [code comprehension](/source/Program_comprehension). The tags are often used by a [source-code editor](/source/Source-code_editor) to lookup the definition of an identifier while the user develops the source code. Alternatively, the command supports an output format that is a [human-readable](/source/Human-readable) [cross reference](/source/Cross_reference).

The original ctags was introduced in [BSD Unix](/source/BSD_Unix) 2.0[1][2] and was written by [Ken Arnold](/source/Ken_Arnold), with [Fortran](/source/Fortran) support by Jim Kleckner and [Pascal](/source/Pascal_(programming_language)) support by [Bill Joy](/source/Bill_Joy). It is part of the initial release of Single Unix Specification and XPG4 of 1992.

## Editor support

Tag index files are supported by many editors, including:

- [Atom](/source/Atom_(text_editor))
- [BBEdit 8+](/source/BBEdit)
- [CodeLite](/source/CodeLite) (via built-in ctagsd [language server](/source/Language_Server_Protocol))[3]
- [Cloud9 IDE](/source/Cloud9_IDE) (uses it internally but does not expose it)
- [CygnusEd](/source/CygnusEd)[4]
- [Emacs](/source/Emacs) and [XEmacs](/source/XEmacs)
- [EmEditor Professional](/source/EmEditor)
- [Far Manager](/source/Far_Manager) (via Ctags Source Navigator plugin)
- [Geany](/source/Geany)
- [Gedit](/source/Gedit) (via [gedit-symbol-browser-plugin](https://web.archive.org/web/20080117145432/http://www.micahcarrick.com/11-14-2007/gedit-symbol-browser-plugin.html))
- [JED](/source/JED_(text_editor))
- [jEdit](/source/JEdit) (via plugins CodeBrowser, Tags, ClassBrowser, CtagsSideKick, or Jump)
- [JOE](/source/Joe's_Own_Editor)
- [KDevelop](/source/KDevelop)
- [Kate](/source/Kate_(text_editor))
- [mcedit](/source/Mcedit) (Midnight Commander builtin editor)
- [NEdit](/source/NEdit)
- [Notepad++](/source/Notepad%2B%2B) (via OpenCTags plug-in)
- QDevelop
- [TSE (via macro)](/source/The_SemWare_Editor)
- [TextMate](/source/TextMate) (via CodeBrowser-PlugIn)
- [UltraEdit](/source/UltraEdit)
- [TextPad](/source/TextPad)
- [VEDIT](/source/VEDIT)
- [vi](/source/Vi_(text_editor)) (and derivatives such as [Elvis](/source/Elvis_(text_editor)), [Nvi](/source/Nvi), [Vim](/source/Vim_(text_editor)), [vile](/source/Vile_(text_editor)), etc.)
- [Visual Studio Code](/source/Visual_Studio_Code)[5]
- [Xedit (X11)](/source/Xedit_(X11))

## Variants

### Original

The original ctags command is generally not supported today but its functionality is still commonly available today via programs that are similar and possibly compatible. In particular, the original tag data format is still commonly used.

The original format, often used with *vi* and its clones as well as by the modern descendent programs Exuberant and Universal Ctags.[6] A tags file, normally named "tags", consists of lines formatted as:

{**tagname**}\t{**tagfile**}\t{**tagaddress**}

The fields are:

- {tagname} – Identifier not containing white space
- \t – Exactly one [tab](/source/Tab_key) (\x09) character, although many versions of *vi* can handle any amount of white space
- {tagfile} – The name of the file where {tagname} is defined, relative to the current directory
- {tagaddress} – An [ex](/source/Ex_(text_editor)) mode command that will take the editor to the location of the tag. To protect against execution of arbitrary commands (for example, commands that modify files), POSIX implementations of *vi* only allow a search command or a line number here.

The lines are sorted on {tagname} which allows for fast searching.

### Extended Ctags

The format used by [Vim](/source/Vim_(text_editor))'s Exuberant Ctags and Universal Ctags. These programs can generate an original *ctags* file format or an extended format that attempts to retain backward compatibility.

A file consists of lines formatted as:

{**tagname**}\t{**tagfile**}\t{**tagaddress**}[;"\t{**tagfield**...}]

The fields up to and including {tagaddress} are the same as for the original ctags format. Optional, additional fields (indicated by square brackets) include:

- ;" – semicolon + double quote: Ends the {tagaddress} in a way that looks like the start of a comment to *vi* or *ex*
- {tagfield} – extension fields: tab separated "key:value" pairs for more information

This format is compatible with non-POSIX *vi* as the additional data is interpreted as a comment. POSIX implementations of *vi* must be changed to support it, however.[6]

### etags

GNU [Emacs](/source/Emacs) comes with two ctags variants, etags and ctags, which are [built](/source/Software_build) from the same source code. etags generates a tag table file for Emacs, and ctags creates a tags file for [vi](/source/Vi_(text_editor)). Some options (e.g. --language) are accepted by both ctags and etags. Options which only make sense when generating a vi-style tags file are not accepted (and are therefore reported as errors) by etags. Similarly ctags does not accept options which are pertinent only to generating a tag table file for Emacs.[7]

For Emacs, the tags file is normally named "TAGS". The file consists of multiple sections – one section per input source file. Sections are plain-text with several non-printable [ASCII](/source/ASCII) characters used for special purposes. These characters are represented as underlined hexadecimal codes below.

A section starts with a two line header (the first two bytes make up a [magic number](/source/Magic_number_(programming))):

\x0c {**src_file**},{**size_of_tag_definition_data_in_bytes**}

Note, \x## represents the byte in hexadecimal ##. Every line ends with a [line feed](/source/Line_feed) (LF, \n = \x0A).

The header is followed by tag definitions, one definition per line, with the format:

{**tag_definition_text**}\x7f{**tagname**}\x01{**line_number**},{**byte_offset**}

{tagname}\x01 can be omitted if the name of the tag can be deduced from the text at the tag definition.

### Exuberant Ctags

Exuberant Ctags, written and maintained by Darren Hiebert until 2009,[8] was initially distributed with [Vim](/source/Vim_(text_editor)), but became a separate project upon the release of Vim 6. It includes support for Emacs and etags compatibility.[9][10]

Exuberant Ctags includes support for over 40 programming languages with the ability to add support for even more using [regular expressions](/source/Regular_expression).

### Universal Ctags

Universal Ctags is a fork of Exuberant Ctags, with the objective of continuing its development. A few parsers are rewritten to better support the languages.[11]

====== Creates a ctags-compatible tag file for [Haskell](/source/Haskell_(programming_language)) source files.[12] It includes support for creating Emacs etags files.[13]

====== A ctags-compatible solution specialized for [JavaScript](/source/JavaScript) using the [CommonJS](/source/CommonJS) packaging system.[14] It outperforms Exuberant Ctags for JavaScript code, finding more tags than the latter.[15]

## Example

Given a single line test.c source code:

1. define CCC(x)

The ctags tag file looks like:

CCC(	test.c	1

The etags tag file (TAGS) looks like this:

\x0c test.c,21

1. define CCC(\x7fCCC\x011,0

## See also

- [GNU GLOBAL](/source/GNU_GLOBAL)

## References

1. ["2BSD/man/ctags.u"](https://www.tuhs.org/cgi-bin/utree.pl?file=2BSD/man/ctags.u). *www.tuhs.org*. [Archived](https://web.archive.org/web/20241130182330/https://www.tuhs.org/cgi-bin/utree.pl?file=2BSD/man/ctags.u) 2024-11-30 at the Wayback Machine. Retrieved 2024-10-21.

1. ["2BSD/src/ctags.sh"](https://www.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/ctags.sh). *www.tuhs.org*. Retrieved 2024-10-21.

1. ["Language Server Protocol"](https://docs.codelite.org/plugins/lsp/). *CodeLite Documentation*. [Archived](https://web.archive.org/web/20220811175133/https://docs.codelite.org/plugins/lsp/) 2022-08-11 at the Wayback Machine. Retrieved 2022-06-12.

1. ["Aminet - dev/C/Ctags.lha"](http://aminet.net/package/dev/c/ctags). [Archived](https://web.archive.org/web/20210413132247/http://aminet.net/package/dev/c/ctags) 2021-04-13 at the Wayback Machine. Retrieved 2021-04-13.

1. [Workspace Symbols](https://donjayamanne.github.io/pythonVSCodeDocs/docs/workspaceSymbols/) [Archived](https://web.archive.org/web/20210111180338/https://donjayamanne.github.io/pythonVSCodeDocs/docs/workspaceSymbols/) 2021-01-11 at the Wayback Machine, *Python for Visual Studio Code Docs*

1. ["Proposal for extended Vi tags file format"](https://ctags.sourceforge.net/FORMAT). [Archived](https://web.archive.org/web/20070612024812/http://ctags.sourceforge.net/FORMAT) 2007-06-12 at the Wayback Machine. Retrieved 2007-06-30.

1. ["Exuberant Ctags"](https://ctags.sourceforge.net/). *ctags.sourceforge.net*. [Archived](https://web.archive.org/web/20250813052221/https://ctags.sourceforge.net/) 2025-08-13 at the Wayback Machine. Retrieved 2025-08-09.

1. ["Vim documentation: version6: ctags-gone"](http://vimdoc.sourceforge.net/htmldoc/version6.html#ctags-gone). [Archived](https://web.archive.org/web/20070503150136/http://vimdoc.sourceforge.net/htmldoc/version6.html#ctags-gone) 2007-05-03 at the Wayback Machine. Retrieved 2007-04-28.

1. ["Universal Ctags Documentation"](https://docs.ctags.io/). Retrieved 2018-08-02.

1. ["GHC documentation: Other Haskell utility programs"](http://haskell.org/ghc/docs/latest/html/users_guide/utils.html#hasktags). [Archived](https://web.archive.org/web/20100325175334/http://haskell.org/ghc/docs/latest/html/users_guide/utils.html#hasktags) 2010-03-25 at the Wayback Machine. Retrieved 2010-03-05.

1. ["hasktags: Produces ctags "tags" and etags "TAGS" files for Haskell programs"](http://hackage.haskell.org/package/hasktags). [Archived](https://web.archive.org/web/20100225063100/http://hackage.haskell.org/package/hasktags) 2010-02-25 at the Wayback Machine. Retrieved 2010-03-05.

1. ["pcwalton github repository for jsctags"](https://web.archive.org/web/20100822181929/http://github.com/pcwalton/jsctags). *[GitHub](/source/GitHub)*. Archived from [the original](https://github.com/pcwalton/jsctags) on 2010-08-22. Retrieved 2016-09-10.

1. Patrick Walton (25 May 2010). ["Introducing jsctags"](https://pcwalton.blogspot.com/2010/05/introducing-jsctags.html). [Archived](https://web.archive.org/web/20100601113914/http://pcwalton.blogspot.com/2010/05/introducing-jsctags.html) 2010-06-01 at the Wayback Machine. Retrieved 2010-05-25.

## External links

- [Universal Ctags homepage](https://ctags.io)
- [Exuberant Ctags homepage](http://ctags.sourceforge.net)
- [Ctags on VMS](http://polarhome.com/ctags/?lang=en)
- [source code for Emacs vtags.el module](http://cvs.savannah.gnu.org/viewvc/vtags/vtags/vtags.el?view=markup)

---
Adapted from the Wikipedia article [Ctags](https://en.wikipedia.org/wiki/Ctags) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Ctags?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
