ETAGS(1)
๐
GNU etags(1) โ tag table era, bestie ๐
okay so this is the GNU etags manual page, and honestly? Itโs giving โquiet little tool that secretly runs your whole code-navigation situation.โ No cap. Letโs get into it ๐ซถ
๐ NAME ๐
etags โ generate tag file for Emacs, vi
โจ SYNOPSIS โจ
There are two synopsis moods here, and yes, the second one starts with --ctags. Keep the options exactly as they are, bestie โ no renaming, no merging, no โfixingโ the vibes.
etags [-aCDGIQRVh] [-i file] [-l language]
[-o tagfile] [-r regexp] [--parse-stdin=file]
[--append] [--no-defines] [--globals] [--no-globals]
[--no-line-directive] [--include=file] [--ignore-indentation]
[--language=language] [--members] [--no-members] [--output=tagfile]
[--class-qualify] [--regex=regexp] [--no-regex] [--no-fallback-lang]
[--fallback-lang] [--no-empty-file-entries] [--empty-file-entries]
[--help] [--version] file ...
And the --ctags form:
etags --ctags [-aCdgIQRVh] [-BtTuvwx] [-l language]
[-o tagfile] [-r regexp] [--parse-stdin=file]
[--append] [--backward-search] [--cxref] [--no-defines] [--globals]
[--no-globals] [--no-line-directive] [--ignore-indentation]
[--language=language] [--members] [--no-members] [--class-qualify]
[--output=tagfile] [--regex=regexp] [--update] [--help] [--version] file
...
๐ธ DESCRIPTION ๐ธ
So the etags program is used to create a tag table file, in a format understood by emacs(1). If the first argument is the obsolescent option --ctags, the program instead creates a similar table in a format understood by vi(1). Obsolescent is the key word there, bestie โ noted, not erased ๐
The program understands the syntax of C, Objective C, C++, Java, Fortran, Ada, Cobol, Erlang, Forth, Go, HTML, LaTeX, Emacs Lisp/Common Lisp, Lua, Makefile, Mercury, Pascal, Perl, Ruby, Rust, PHP, PostScript, Python, Prolog, Scheme and most assembler-like syntaxes. Like, the range? Iconic. ๐
It reads the files specified on the command line and writes a tag table in the current working directory. The default tag table name is TAGS, or tags if --ctags is used. Defaults stay exactly as they are โ we donโt improvise here, periodt.
Files specified with relative file names will be recorded in the tag table with file names relative to the directory where the tag table resides. If the tag table is in /dev or is the standard output, however, the file names are made relative to the working directory. Files specified with absolute file names will be recorded with absolute file names. The path rules are lowkey doing the most, but theyโre doing it consistently โจ
Files generated from a source file โ like a C file generated from a source Cweb file โ will be recorded with the name of the source file. That detail matters, so it stays ๐
Compressed files are supported using gzip, bzip2, xz, and zstd. The programs recognize the language used in an input file based on its file name and contents. And if you need to override the guessy-guess era, the --language switch can be used to force parsing of the file names following the switch according to the given language, overriding guesses based on filename extensions. Slay. ๐ฆ
โจ OPTIONS โจ
okay so quick heads-up before the list: some of these options only make sense for vi style tag files, the ones you get with --ctags โ otherwise they just get ignored, no drama. also, both programs are chill and accept unambiguous abbreviations for long option names (so you can be lazy, but not ambiguous lazy ๐
).
-a,--appendโ append to the existing tag file instead of starting fresh. (For vi-format tag files, also go look at--update.)-B,--backward-searchโ so tag files written in the format vi expects contain regular expression search instructions, right?-Bwrites those using the delimiter"?", which searches backwards through files. the default is the delimiter"/", which searches forwards. only makes sense if--ctagsis in play.--declarationsโ in C and derived languages, this creates tags for function declarations, and creates tags for extern variables unless--no-globalsis used. in Lisp, it creates tags for(defvar foo)declarations. in Mercury, declarations start a line with":-"and are always tagged. bonus: this option also tags predicates or functions in first rules of clauses, as in Prolog. iconic multitasker behavior ๐-D,--no-definesโ do not create tag entries for C preprocessor constant definitions and enum constants. ngl this can make the tags file way smaller if you've got a ton of header files being tagged.--globalsโ create tag entries for global variables in Perl and Makefile. this one is already the default in C and derived languages.--no-globalsโ do not tag global variables in C and derived languages. typically this cuts the file size by one fourth, so, slay for your disk.--no-line-directiveโ ignore#linepreprocessor directives in C and derived languages. the default is to honor those directives and record the tags as if the file scanned was the one named in the#linedirective. this switch is your bestie when the original file named by#lineisn't available anymore ๐ซถ-i file,--include=fileโ drops a note in the tag file saying that when you're searching for a tag, you should also consult the tags file file after checking the current file. onlyetagsaccepts this option,ctagssaid no thanks.-I,--ignore-indentationโ don't rely on indentation as much as we normally do. currently that means: don't assume a closing brace in the first column is the final brace of a function or structure definition in C and C++. this matters for code that does not follow the GNU Coding conventions of putting only top-level braces in column zero. honestly, chaotic formatting deserves love too ๐ญ-l language,--language=languageโ parse the files that come after according to the given language. you can mix more than one of these in with filenames, no problem. use--helpto get a list of the available languages and their default filename extensions. for example, since Mercury and Objective-C both rock the same filename extension.m, a test based on contents tries to detect the language. if that test fails, use--language=mercuryor--language=objc. the"auto"language restores automatic detection of language based on the file name. the"none"language disables language parsing altogether โ in that case only regexp matching happens (see the--regexoption).--membersโ create tag entries for variables that are members of structure-like constructs in PHP. this is the default for C and derived languages.--no-membersโ do not tag member variables. simple as that ๐ฆ--packages-onlyโ only tag packages in Ada files. that's it, that's the whole vibe.--parse-stdin=fileโ may be used (only once!) in place of a file name on the command line.etagswill read from standard input and mark the produced tags as belonging to the file FILE. one-time guest star energy โญ-Q,--class-qualifyโ qualify tag names with their class name in C++, ObjC, Java, and Perl. this gives you tag names of the formclass::memberfor C++ and Perl,class(category)for Objective C, andclass.memberfor Java. for Objective C, it also produces class methods qualified with their arguments, as infoo:bar:baz:more. very demure, very qualified ๐-o tagfile,--output=tagfileโ explicit name of the file for the tag table. foretagsonly, a file name of-means standard output. overrides the defaultTAGSortags. (but it gets ignored with-vor-x, sorry bestie.)-r regexp,--regex=regexpโ makes tags based on regexp matching for the files that follow this option, in addition to the tags made with the standard parsing based on language. you can freely intermix it with filenames and the-Roption. the regexps are cumulative, i.e., each such option adds to the previous ones. the regexps are one of these two forms:
[{language}]/tagregexp/[nameregexp/]modifiers
@regexfile
where tagregexp is used to match the tag. it should not match useless characters. if the match is such that more characters than needed are unavoidably matched by tagregexp, it may be useful to add a nameregexp to narrow down the tag scope. --ctags ignores regexps without a nameregexp. the syntax of regexps is the same as in Emacs, except that backslash escapes are the same as GNU grep (which means, for example, that shy groups are not supported), and [:ascii:], [:multibyte:], [:nonascii:], [:word:], and [:unibyte:] are not supported. these character escape sequences are supported: \a, \b, \d, \e, \f, \n, \r, \t, \v, which respectively stand for the ASCII characters BEL, BS, DEL, ESC, FF, NL, CR, TAB, VT.
the modifiers are a sequence of 0 or more characters among i, which means to ignore case when matching; m, which means the tagregexp will be matched against the whole file contents at once rather than line by line, and the matching sequence can match multiple lines; and s, which implies m and means the dot character in tagregexp matches the newline char as well.
the separator, which is / in the examples, can be any character different from space, tab, braces and @. if the separator character is needed inside the regular expression, it must be quoted by preceding it with \.
the optional {language} prefix means the tag should be created only for files of language language, and ignored otherwise. this is especially handy when you're storing a bunch of predefined regexps in a file.
in its second form, regexfile is the name of a file containing a number of arguments to the --regex= option, one per line. lines beginning with a space or tab are assumed to be comments, and ignored.
here are some examples. all the regexps are quoted to protect them from shell interpretation, bestie, don't forget:
tag the DEFVAR macros in the emacs source files:
--regex='/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
tag VHDL files (this example is a single long line, broken here for formatting reasons):
--language=none --regex='/[ \t]*\(ARCHITECTURE\|\ CONFIGURAโ
TION\) +[^ ]* +OF/' --regex='/[ \t]*\ \(ATTRIBUTE\|ENTITY\|FUNCโ
TION\|PACKAGE\( BODY\)?\ \|PROCEโ
DURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
tag Tcl files (this last example shows the usage of a tagregexp):
--lang=none --regex='/proc[ \t]+\([^ \t]+\)/\1/'
a regexp can be preceded by {lang}, which restricts it to match lines of files of the specified language. use etags --help to obtain a list of the recognized languages. this feature is particularly useful inside regex files. a regex file contains one regex per line. empty lines, and those lines beginning with space or tab, are ignored. lines beginning with @ are references to regex files whose name follows the @ sign. other lines are considered regular expressions like those following --regex. for example, the command
etags --regex=@regex.file *.c
reads the regexes contained in the file regex.file. extremely efficient, we love a shortcut ๐ธ
-R,--no-regexโ don't do any more regexp matching on the following files. can be freely intermixed with filenames and the--regexoption. it's giving "we're done here" energy ๐--fallback-langโ if a file's language cannot be determined, attempt to parse it as Fortran and C/C++. this is the default, so it's already doing the most for you.--no-fallback-langโ do not fall back to Fortran and C/C++ for files whose language could not be determined.--empty-file-entriesโ produce file entries for files with no tags. this is the default.--no-empty-file-entriesโ do not output file entries for files with no tags.-u,--updateโ update tag entries for files specified on the command line, leaving tag entries for other files in place. currently this is implemented by deleting the existing entries for the given files and then rewriting the new entries at the end of the tags file. honestly it's often faster to simply rebuild the entire tag file than to use this. only makes sense if--ctagsis used, iykyk.-v,--vgrindโ instead of generating a tag file, write an index (in vgrind format) to standard output. only makes sense if--ctagsis used.-x,--cxrefโ instead of generating a tag file, write a cross reference (in cxref format) to standard output. only makes sense if--ctagsis used.-h,-H,--helpโ print usage information. follow it with one or more--language=LANGand it prints detailed information about how tags are created for LANG. the little helper we all deserve ๐ซถ-V,--versionโ print the current version of the program (same as the version of the emacs etags it is shipped with).
๐ธ SEE ALSO ๐ธ
- the
"emacs"entry in info; GNU Emacs Manual, Richard Stallman. cxref(1),emacs(1),vgrind(1),vi(1).
๐ COPYING ๐
Okay so legal time, bestie โ don't scroll, this actually matters ๐
Copyright 1992, 1999, 2001โ2026 Free Software Foundation, Inc.
Here's the deal, in three little permission slips:
- Permission is granted to make and distribute verbatim copies of this document โ provided the copyright notice and this permission notice are preserved on all copies. That's it. Keep the receipts attached and you're golden ๐ซถ
- Permission is granted to copy and distribute modified versions of this document under the same conditions as verbatim copying โ provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. So like, remix it, slay, but the fine print has to stay the same fine print โจ
- Permission is granted to copy and distribute translations of this document into another language, under the above conditions for modified versions โ with one exception: this permission notice may be stated in a translation approved by the Free Software Foundation. No freelance translating the legal notice without FSF approval, iykyk ๐ธ
And that's the whole page, bestie โ you made it to the end ๐
This iconic little artifact is from GNU Tools, dated 2025-03-22, and it lives in the man page universe as ETAGS(1). Go tag some files, you absolute main character ๐๐
๐ฆ where this page comes from
- arch rolling: emacs 31.1-2 ยท GPL-3.0-or-later
- arch rolling: emacs-nox 31.1-2 ยท GPL-3.0-or-later
- arch rolling: emacs-wayland 31.1-2 ยท GPL-3.0-or-later
- nixpkgs unstable: emacs 31.1
- nixpkgs unstable: emacs-gtk3 31.1
- nixpkgs unstable: emacs-nox 31.1
- nixpkgs unstable: emacs-pgtk 31.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms