ctags command in Linux system is used for the with the classic editors. It allows quick access across the files (For example quickly seeing definition of a function). A user can run tags or ctags inside a directory to create a simple index of the source files while working on. Tags-capable editors like vi/vim can then refer to these tags index file to allow you to follow references. Basically, this command generates the tag files for source code. It is also used to create a cross reference file which lists and contain the information about the various source objects found in a set of human-readable language files.
ctags [options] [file(s)]
- –help: It will print the general syntax of the command along with the various options that can be used with the ctags command as well as gives a brief description about each option.
- ctags -a: This option used to append the tags to an existing tag file. Equivalent to –append. [Ignored with -e]
- ctags -B: This option used for backward searching patterns (e.g. ?regexp?). [Ignored with -e]
- ctags -e: This option used for output a tag file for use with Emacs. If this program is being executed by the name etags, this option is already enabled by default.
- ctags -F: This option used for searching patterns (e.g. /regexp/)(default). [Ignored with -e]
- ctags -i: This option is similar to the –c-types option and is retained for all the compatibility with earlier versions.
- ctags -n: This option is Equivalent to –excmd=number.
- ctags -N: This option is Equivalent to –excmd=pattern.
- ctags -o: This option is Equivalent to -f tagfile.
- ctags -p: This option is Used path as the default directory for each supplied source file, unless the source file is already specified as an absolute path.
- ctags -R: This option is Equivalent to –recurse=yes.
- ctags -u: This option is Equivalent to –sort=no (i.e. “unsorted”).
- ctags -V: This option Enables the verbose mode. This prints out a brief message describing that what action is being taken for each of the file considered by ctags.
ctags with Vim:
- cd to the folder of your choice where your file is located:
Run ctags recursively over the entire folder of your choice to generate the tags file
- Now run this command:
ctags -R *
- To search for a specific tag and open the output in Vim to its definition, run the following command in your shell:
vim -t "tag"
vim -t title
As a result this screen pops up with the matching result:
- apt command in linux with examples
- ip command in Linux with examples
- cal command in Linux with Examples
- if command in linux with examples
- cc command in Linux with Examples
- cut command in Linux with examples
- man command in Linux with Examples
- rev command in Linux with Examples
- top command in Linux with Examples
- cp command in Linux with examples
- atq command in linux with examples
- dir command in Linux with examples
- ps command in Linux with Examples
- which command in Linux with examples
- help Command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.