.\" Man page generated from reStructuredText. . .TH CTAGS-FAQ 7 "" "5.9.0" "Universal Ctags" .SH NAME ctags-faq \- Universal Ctags FAQ . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .sp This is the Universal Ctags FAQ (Frequently\-Asked Questions). It is based on \fI\%Exuberant Ctags FAQ\fP .SS Contents .INDENT 0.0 .IP \(bu 2 \fI\%DESCRIPTION\fP .INDENT 2.0 .IP \(bu 2 \fI\%What is the difference between Universal Ctags and Exuberant Ctags?\fP .IP \(bu 2 \fI\%How can I avoid having to specify my favorite option every time?\fP .IP \(bu 2 \fI\%What are these strange bits of text beginning with \fB;"\fP which follow many of the lines in the tag file?\fP .IP \(bu 2 \fI\%Why can\(aqt I jump to \fBclass::member\fP?\fP .IP \(bu 2 \fI\%Why do I end up on the wrong line when I jump to a tag?\fP .IP \(bu 2 \fI\%How do I jump to the tag I want instead of the wrong one by the same name?\fP .IP \(bu 2 \fI\%How can I locate all references to a specific function or variable?\fP .IP \(bu 2 \fI\%Why does appending tags to a tag file tag so long?\fP .IP \(bu 2 \fI\%How should I set up tag files for a multi\-level directory hierarchy?\fP .IP \(bu 2 \fI\%Does Universal Ctags support Unicode file names?\fP .IP \(bu 2 \fI\%Why does zsh cause "zsh: no matches found" error?\fP .UNINDENT .IP \(bu 2 \fI\%SEE ALSO\fP .IP \(bu 2 \fI\%AUTHOR\fP .UNINDENT .SH DESCRIPTION .\" TODO: https://github.com/universal-ctags/ctags/issues/2312 .\" #1421: feature: clean up stale tags when appending (`-a`) .\" #2356: can't pre-process the macro but it works with Exuberant Ctags 5.8 .\" #2540: C/C++:conditional compilation like #ifdef will cause parse errror . .SS What is the difference between Universal Ctags and Exuberant Ctags? .sp Universal Ctags is an unofficial fork of Exuberant Ctags. The differences are summarized in ctags\-incompatibilities(7) man page. .sp The most notable one is that Universal Ctags doesn\(aqt read \fB~/.ctags\fP file. Instead, it reads \fB*.ctags\fP under \fB~/.ctags.d\fP directory. .SS How can I avoid having to specify my favorite option every time? .sp Either by setting the environment variable \fBCTAGS\fP to your custom options, or putting them into a \fB~/.ctags.d/anyname.ctags\fP file in your home directory. .SS What are these strange bits of text beginning with \fB;"\fP which follow many of the lines in the tag file? .sp These are \fIextension flags\fP\&. They are added in order to provide extra information about the tag that may be utilized by the editor in order to more intelligently handle tags. They are appended to the EX command part of the tag line in a manner that provides backwards compatibility with existing implementations of the Vi editor. The semicolon is an EX command separator and the double quote begins an EX comment. Thus, the extension flags appear as an EX comment and should be ignored by the editor when it processes the EX command. .sp Some non\-vi editors, however, implement only the bare minimum of EX commands in order to process the search command or line number in the third field of the tag file. If you encounter this problem, use the option \fB\-\-format=1\fP to generate a tag file without these extensions (remember that you can set the CTAGS environment variable to any default arguments you wish to supply). Then ask the supplier of your editor to implement handling of this feature of EX commands. .SS Why can\(aqt I jump to \fBclass::member\fP? .sp Because, by default, ctags only generates tags for the separate identifiers found in the source files. If you specify the \fB\-\-extra=+q\fP option, then ctags will also generate a second, class\-qualified tag for each class member (data and function/method) in the form \fBclass::member\fP for C++, and in the form \fBclass.method\fP for Eiffel and Java. .SS Why do I end up on the wrong line when I jump to a tag? .sp By default, ctags encodes the line number in the file where macro (\fB#define\fP) tags are found. This was done to remain compatible with the original UNIX version of ctags. If you change the file containing the tag without rebuilding the tag file, the location of tag in the tag file may no longer match the current location. .sp In order to avoid this problem, you can specify the option \fB\-\-excmd=p\fP, which causes ctags to use a search pattern to locate macro tags. I have never uncovered the reason why the original UNIX ctags used line numbers exclusively for macro tags, but have so far resisted changing the default behavior of Exuberant (and Universal) Ctags to behave differently. .SS How do I jump to the tag I want instead of the wrong one by the same name? .sp A tag file is simple a list of tag names and where to find them. If there are duplicate entries, you often end up going to the wrong one because the tag file is sorted and your editor locates the first one in the tag file. .sp Standard Vi provides no facilities to alter this behavior. However, Vim has some nice features to minimize this problem, primarily by examining all matches and choosing the best one under the circumstances. Vim also provides commands which allow for selection of the desired matching tag. .SS How can I locate all references to a specific function or variable? .sp There are several packages already available which provide this capability. Namely, these are: GLOBAL source code tag system, GNU id\-utils, cscope, and cflow. As of this writing, they can be found in the following locations: .INDENT 0.0 .IP \(bu 2 GLOBAL: \fI\%http://www.gnu.org/software/global\fP .IP \(bu 2 id\-utils: \fI\%http://www.gnu.org/software/idutils/idutils.html\fP .IP \(bu 2 cscope: \fI\%http://cscope.sourceforge.net\fP .IP \(bu 2 cflow: \fI\%ftp://www.ibiblio.org/pub/Linux/devel/lang/c\fP .UNINDENT .SS Why does appending tags to a tag file tag so long? .sp Sometimes, in an attempt to build a global tag file for all source files in a large source tree of many directories, someone will make an attempt to run ctags in append (\fB\-a\fP) mode on every directory in the hierarchy. Each time ctags is invoked, its default behavior is to sort the tag file once the tags for that execution have been added. As the cumulative tag file grows, the sort time increases arithmetically. .sp The best way to avoid this problem (and the most efficient) is to make use of the \fB\-\-recurse\fP (or \fB\-R\fP) option of ctags by executing the following command in the root of the directory hierarchy (thus running ctags only once): .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C ctags \-R .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp If you really insist on running ctags separately on each directory, you can avoid the sort pass each time by specifying the option \fB\-\-sort=no\fP\&. Once the tag file is completely built, use the sort command to manually sort the final tag file, or let the final invocation of ctags sort the file. .SS How should I set up tag files for a multi\-level directory hierarchy? .sp There are a few ways of approaching this: .INDENT 0.0 .IP 1. 3 A local tag file in each directory containing only the tags for source files in that directory. .IP 2. 3 One single big, global tag file present in the root directory of your hierarchy, containing all tags present in all source files in the hierarchy. .IP 3. 3 A local tag file in each directory containing only the tags for source files in that directory, in addition to one single global tag file present in the root directory of your hierarchy, containing all non\-static tags present in all source files in the hierarchy. .IP 4. 3 A local tag file in each directory of the hierarchy, each one containing all tags present in source files in that directory and all non\-static tags in every directory below it (note that this implies also having one big tag file in the root directory of the hierarchy). .UNINDENT .sp Each of these approaches has its own set of advantages and disadvantages, depending upon your particular conditions. Which approach is deemed best depends upon the following factors: .INDENT 0.0 .IP A. 3 The ability of your editor to use multiple tag files. .sp If your editor cannot make use of multiple tag files (original vi implementations could not), then one large tag file is the only way to go if you ever desire to jump to tags located in other directories. If you never need to jump to tags in another directory (i.e. the source in each directory is entirely self\-contained), then a local tag file in each directory will fit your needs. .IP B. 3 The time is takes for your editor to look up a tag in the tag file. .sp The significance of this factor depends upon the size of your source tree and on whether the source files are located on a local or remote file system. For source and tag files located on a local file system, looking up a tag is not as big a hit as one might first imagine, since vi implementations typically perform a binary search on a sorted tag file. This may or may not be true for the editor you use. For files located on a remote file system, reading a large file is an expensive operation. .IP C. 3 Whether or not you expect the source code to change and the time it takes to rebuild a tag file to account for changes to the source code. .sp While Universal Ctags is particularly fast in scanning source code (around 1\-2 MB/sec), a large project may still result in objectionable delays if one wishes to keep their tag file(s) up to date on a frequent basis, or if the files are located on a remote file system. .IP D. 3 The presence of duplicate tags in the source code and the ability to handle them. .sp The impact of this factor is influenced by the following three issues: .INDENT 3.0 .IP 1. 3 How common are duplicate tags in your project? .IP 2. 3 Does your editor provide any facilities for dealing with duplicate tags? .sp While standard vi does not, many modern vi implementations, such as Vim have good facilities for selecting the desired match from the list of duplicates. If your editor does not support duplicate tags, then it will typically send you to only one of them, whether or not that is the one you wanted (and not even notifying you that there are other potential matches). .IP 3. 3 What is the significance of duplicate tags? .sp For example, if you have two tags of the same name from entirely isolated software components, jumping first to the match found in component B while working in component A may be entirely misleading, distracting or inconvenient (to keep having to choose which one if your editor provides you with a list of matches). However, if you have two tags of the same name for parallel builds (say two initialization routines for different hosts), you may always want to specify which one you want. .UNINDENT .UNINDENT .sp Of the approaches listed above, I tend to favor Approach 3. My editor of choice is Vim, which provides a rich set of features for handling multiple tag files, which partly influences my choice. If you are working with source files on a remote file system, then I would recommend either Approach 3 or Approach 4, depending upon the hit when reading the global tag file. .sp The advantages of Approach 3 are many (assuming that your editor has the ability to support both multiple tag files and duplicate tags). All lookups of tag located in the current directory are fast and the local tag file can be quickly and easily regenerated in one second or less (I have even mapped a keystroke to do this easily). A lookup of a (necessarily non\-static) tag found in another directory fails a lookup in the local tag file, but is found in the global tag file, which satisfies all cross\-directory lookups. The global tag file can be automatically regenerated periodically with a cron job (and perhaps the local tag files also). .sp Now I give an example of how you would implement Approach 3. Means of implementing the other approaches can be performed in a similar manner. .sp Here is a visual representation of an example directory hierarchy: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C project \(ga\-\-\-\-\-misccomp | \(ga... \(ga\-\-\-\-\-sysint \(ga\-\-\-\-\-client | \(ga\-\-\-\-\-hdrs | \(ga\-\-\-\-\-lib | \(ga\-\-\-\-\-src | \(ga\-\-\-\-\-test \(ga\-\-\-\-\-common | \(ga\-\-\-\-\-hdrs | \(ga\-\-\-\-\-lib | \(ga\-\-\-\-\-src | \(ga\-\-\-\-\-test \(ga\-\-\-\-\-server \(ga\-\-\-\-\-hdrs \(ga\-\-\-\-\-lib \(ga\-\-\-\-\-src \(ga\-\-\-\-\-test .ft P .fi .UNINDENT .UNINDENT .sp Here is a recommended solution (conceptually) to build the tag files: .INDENT 0.0 .IP 1. 3 Within each of the leaf nodes (i.e. \fBhdrs\fP, \fBlib\fP, \fBsrc\fP, \fBtest\fP) build a tag file using "\fBctags *.[ch]\fP". This can be easily be done for the whole hierarchy by making a shell script, call it \fBdirtags\fP, containing the following lines: .INDENT 3.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #!/bin/sh cd $1 ctags * .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp Now execute the following command: .INDENT 3.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C find * \-type d \-exec dirtags {} \e; .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp These tag files are trivial (and extremely quick) to rebuild while making changes within a directory. The following Vim key mapping is quite useful to rebuild the tag file in the directory of the current source file: .INDENT 3.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C :nmap ,t :!(cd %:p:h;ctags *.[ch])& .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .IP 2. 3 Build the global tag file: .INDENT 3.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cd ~/project ctags \-\-file\-scope=no \-R .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp thus constructing a tag file containing only non\-static tags for all source files in all descendent directories. .IP 3. 3 Configure your editor to read the local tag file first, then consult the global tag file when not found in the local tag file. In Vim, this is done as follows: .INDENT 3.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C :set tags=./tags,tags,~/project/tags .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp If you wish to implement Approach 4, you would need to replace the \fBdirtags\fP script of step 1 with the following: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #!/bin/sh cd $1 ctags * # Now append the non\-static tags from descendent directories find * \-type d \-prune \-print | ctags \-aR \-\-file\-scope=no \-L\- .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp And replace the configuration of step 3 with this: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C :set tags=./tags;$HOME,tags .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp As a caveat, it should be noted that step 2 builds a global tag file whose file names will be relative to the directory in which the global tag file is being built. This takes advantage of the Vim \fBtagrelative\fP option, which causes the path to be interpreted a relative to the location of the tag file instead of the current directory. For standard vi, which always interprets the paths as relative to the current directory, we need to build the global tag file with absolute path names. This can be accomplished by replacing step 2 with the following: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cd ~/project ctags \-\-file\-scope=no \-R \(gapwd\(ga .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SS Does Universal Ctags support Unicode file names? .\" MEMO: from https://github.com/universal-ctags/ctags/issues/1837 . .sp Yes, Unicode file names are supported on unix\-like platforms (Linux, macOS, Cygwin, etc.). .sp However, on Windows, you need to use Windows 10 version 1903 or later to use Unicode file names. (This is an experimental feature, though.) On older versions on Windows, Universal Ctags only support file names represented in the current code page. If you still want to use Unicode file names on them, use Cygwin or MSYS2 version of Universal Ctags as a workaround. .SS Why does zsh cause "zsh: no matches found" error? .\" MEMO: from https://github.com/universal-ctags/ctags/issues/2842 . .sp zsh causes error on the following cases; .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C ctags \-\-extra=+* ... ctags \-\-exclude=foo/* ... .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp This is the 2nd most significant incompatibility \fIfeature\fP of zsh. .sp Cited from "Z\-Shell Frequently\-Asked Questions", "\fI\%2.1: Differences from sh and ksh\fP"; .INDENT 0.0 .INDENT 3.5 \&... The next most classic difference is that unmatched glob patterns cause the command to abort; set \fBNO_NOMATCH\fP for those. .UNINDENT .UNINDENT .sp You may add "\fBsetopt nonomatch\fP" on your \fB~/.zshrc\fP\&. Or you can escape glob patterns with backslash; .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C ctags \-\-extra=+\e* ... ctags \-\-exclude=foo/\e* ... .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp Or quote them; .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C ctags \(aq\-\-extra=+*\(aq ... ctags \(aq\-\-exclude=foo/*\(aq ... .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH SEE ALSO .sp The official Universal Ctags web site at: .sp \fI\%https://ctags.io/\fP .sp ctags(1), tags(5) .SH AUTHOR .sp This FAQ is based on \fI\%Exuberant Ctags FAQ\fP by Darren Hiebert and \fI\%vberthoux@users.sourceforge.net\fP .sp Universal Ctags project: \fI\%https://ctags.io/\fP .\" Generated by docutils manpage writer. .