Linux command
ctags 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Generate tags for current directory
ctags *
Generate tags recursively
ctags -R
Generate tags for specific files
ctags [file1.c] [file2.c]
Output to specific file
ctags -f [tags] -R [src/]
Append to existing tags file
ctags -a [newfile.c]
List supported languages
ctags --list-languages
List tag kinds for language
ctags --list-kinds=[c]
说明
ctags generates index files (tags) that map identifiers in source code to their definitions. This enables text editors and IDEs to quickly navigate to function definitions, class declarations, variables, and other programming constructs across large codebases. The tool parses source code in dozens of programming languages, extracting symbols like function names, classes, methods, variables, macros, and type definitions. It creates a tags file (default name: tags) containing the symbol name, file location, and search pattern to find it. Modern editors like Vim, Emacs, and many IDEs use ctags files for features like "go to definition," symbol completion, and code navigation. Universal Ctags is the actively maintained fork and supports more languages and features than the original Exuberant Ctags.
参数
- -R, --recurse
- Recurse into directories
- -f _file_, -o _file_
- Output tags to file
- -a, --append
- Append to existing tags file
- -L _file_, --file-list _file_
- Read file names from file
- --languages _list_
- Restrict to languages
- --language-force _lang_
- Force specific language
- --exclude _pattern_
- Exclude files matching pattern
- --extras _flags_
- Extra tag entries
- --fields _flags_
- Fields to include
- --kinds-\<lang\> _kinds_
- Tag kinds to include
- --list-languages
- List supported languages
- --list-kinds=_lang_
- List tag kinds
- --list-maps
- List file extension mappings
FAQ
What is the ctags command used for?
ctags generates index files (tags) that map identifiers in source code to their definitions. This enables text editors and IDEs to quickly navigate to function definitions, class declarations, variables, and other programming constructs across large codebases. The tool parses source code in dozens of programming languages, extracting symbols like function names, classes, methods, variables, macros, and type definitions. It creates a tags file (default name: tags) containing the symbol name, file location, and search pattern to find it. Modern editors like Vim, Emacs, and many IDEs use ctags files for features like "go to definition," symbol completion, and code navigation. Universal Ctags is the actively maintained fork and supports more languages and features than the original Exuberant Ctags.
How do I run a basic ctags example?
Run `ctags *` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -R, --recurse do in ctags?
Recurse into directories