ctags
Page Module:Message box/ambox.css has no content.
This article needs additional citations for verification. (November 2011) |
Page Module:Infobox/styles.css has no content.
| Ctags (BSD) | |
|---|---|
| [[Programmer|DeveloperTemplate:Pluralize from text]] | Ken Arnold |
| Operating system | Unix and Unix-like |
| Platform | Cross-platform |
| Type | Programming tool (Specifically: Code navigation tool) |
| License | BSD |
| Website | Script error: No such module "WikidataIB". |
Script error: No such module "Check for conflicting parameters".
ctags is a shell command that generates an index (tag) file of programmatic identifiers parsed from source code files of various programming languages to aid with code comprehension. The tags are often used by a 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 cross reference.
The original ctags was introduced in BSD Unix 2.0[1][2] and was written by Ken Arnold, with Fortran support by Jim Kleckner and Pascal support by 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:
Page Template:Div col/styles.css has no content.
- Atom
- BBEdit 8+
- CodeLite (via built-in ctagsd language server)[3]
- Cloud9 IDE (uses it internally but does not expose it)
- CygnusEd[4]
- Emacs and XEmacs
- EmEditor Professional
- Far Manager (via Ctags Source Navigator plugin)
- Geany
- Gedit (via gedit-symbol-browser-plugin)
- JED
- jEdit (via plugins CodeBrowser, Tags, ClassBrowser, CtagsSideKick, or Jump)
- JOE
- KDevelop
- Kate
- mcedit (Midnight Commander builtin editor)
- NEdit
- Notepad++ (via OpenCTags plug-in)
- QDevelop
- TSE (via macro)
- TextMate (via CodeBrowser-PlugIn)
- UltraEdit
- TextPad
- VEDIT
- vi (and derivatives such as Elvis, Nvi, Vim, vile, etc.)
- Visual Studio Code[5]
- 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:
- Page Template:Mono/styles.css has no content.{tagname} – Identifier not containing white space
- Page Template:Mono/styles.css has no content.\t – Exactly one tab (Page Template:Mono/styles.css has no content.\x09) character, although many versions of vi can handle any amount of white space
- Page Template:Mono/styles.css has no content.{tagfile} – The name of the file where Page Template:Mono/styles.css has no content.{tagname} is defined, relative to the current directory
- Page Template:Mono/styles.css has no content.{tagaddress} – An ex 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 Page Template:Mono/styles.css has no content.{tagname} which allows for fast searching.
Extended Ctags
The format used by Vim'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 Page Template:Mono/styles.css has no content.{tagaddress} are the same as for the original ctags format. Optional, additional fields (indicated by square brackets) include:
- Page Template:Mono/styles.css has no content.;" – semicolon + double quote: Ends the Page Template:Mono/styles.css has no content.{tagaddress} in a way that looks like the start of a comment to vi or ex
- Page Template:Mono/styles.css has no content.{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 comes with two ctags variants, etags and ctags, which are built from the same source code. etags generates a tag table file for Emacs, and ctags creates a tags file for vi. 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 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):
\x0c
{src_file},{size_of_tag_definition_data_in_bytes}
Note, Page Template:Mono/styles.css has no content.\x## represents the byte in hexadecimal Page Template:Mono/styles.css has no content.##. Every line ends with a line feed (LF, Page Template:Mono/styles.css has no content.\n = Page Template:Mono/styles.css has no content.\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}
Page Template:Mono/styles.css has no content.{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, 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.
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]
Page Template:Visible anchor/styles.css has no content.Hasktags
Creates a ctags-compatible tag file for Haskell source files.[12] It includes support for creating Emacs etags files.[13]
Page Template:Visible anchor/styles.css has no content.jsctags
A ctags-compatible solution specialized for JavaScript using the CommonJS packaging system.[14] It outperforms Exuberant Ctags for JavaScript code, finding more tags than the latter.[15]
Example
Given a single line Page Template:Mono/styles.css has no content.test.c source code:
#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 #define CCC(\x7fCCC\x011,0
See also
References
Page Template:Reflist/styles.css has no content.
- ^ Page Module:Citation/CS1/styles.css has no content."2BSD/man/ctags.u". www.tuhs.org. Archived from the original on 2024-11-30. Retrieved 2024-10-21.
- ^ Page Module:Citation/CS1/styles.css has no content."2BSD/src/ctags.sh". www.tuhs.org. Retrieved 2024-10-21.
- ^ Page Module:Citation/CS1/styles.css has no content."Language Server Protocol". CodeLite Documentation. Archived from the original on 2022-08-11. Retrieved 2022-06-12.
- ^ Page Module:Citation/CS1/styles.css has no content."Aminet - dev/C/Ctags.lha". Archived from the original on 2021-04-13. Retrieved 2021-04-13.
- ^ Workspace Symbols Script error: No such module "webarchive"., Python for Visual Studio Code Docs
- ^ a b Page Module:Citation/CS1/styles.css has no content."Proposal for extended Vi tags file format". Archived from the original on 2007-06-12. Retrieved 2007-06-30.
- ^ Template:Man
- ^ Page Module:Citation/CS1/styles.css has no content."Exuberant Ctags". ctags.sourceforge.net. Archived from the original on 2025-08-13. Retrieved 2025-08-09.
- ^ Page Module:Citation/CS1/styles.css has no content."Vim documentation: version6: ctags-gone". Archived from the original on 2007-05-03. Retrieved 2007-04-28.
- ^ Template:Man
- ^ Page Module:Citation/CS1/styles.css has no content."Universal Ctags Documentation". Retrieved 2018-08-02.
- ^ Page Module:Citation/CS1/styles.css has no content."GHC documentation: Other Haskell utility programs". Archived from the original on 2010-03-25. Retrieved 2010-03-05.
- ^ Page Module:Citation/CS1/styles.css has no content."hasktags: Produces ctags "tags" and etags "TAGS" files for Haskell programs". Archived from the original on 2010-02-25. Retrieved 2010-03-05.
- ^ Page Module:Citation/CS1/styles.css has no content."pcwalton github repository for jsctags". GitHub. Archived from the original on 2010-08-22. Retrieved 2016-09-10.
- ^ Page Module:Citation/CS1/styles.css has no content.Patrick Walton (25 May 2010). "Introducing jsctags". Archived from the original on 2010-06-01. Retrieved 2010-05-25.
External links
Page Module:Side box/styles.css has no content.Page Template:Sister project/styles.css has no content.
- Template:Man
- Universal Ctags homepage
- Exuberant Ctags homepage
- Ctags on VMS
- source code for Emacs vtags.el module
Lua error in package.lua at line 80: module 'Module:Navbox/configuration' not found.