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:
- Cat command in Linux with examples
- tac command in Linux with Examples
- less command in Linux with Examples
- gcc command in Linux with examples
- cvs command in Linux with Examples
- rm command in Linux with examples
- rev command in Linux with Examples
- fc Command in Linux with Examples
- cpp command in Linux with Examples
- col command in Linux with Examples
- ps command in Linux with Examples
- atd command in Linux with examples
- df command in Linux with Examples
- yes command in Linux with Examples
- man 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 email@example.com. 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.