The tags module and ctags of VIM

Source: Internet
Author: User
Tags tagname
1. Overview

In general, jump in code is inseparable from ctags.

In fact, the Code redirection in VIM is completed by the vim tags module, and the tags module depends on the tags file.

Ctags (generate tag files for source code) generate the tags file.

The tags file only contains the definition information of functions, classes, and variables, but does not contain the usage information.

If you want to know where a function has been used, you need to use cscope.

2. Generate and update the tags File

By default, ctags does not automatically generate the ctags file. The following are commonly used three generation commands:

$ ctags *$ ctags -R$ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
  • -R: generate the tags of the subdirectory cyclically.
  • *: All files in the current directory are not recursive.
  • -C ++-kinds = + px: records the function declarations in the C ++ file and various external and forward declarations.
  • -Fields = + IAS: the information described by ctags. I indicates that the parent class is identified if there is inheritance. A indicates that if the element is a class member, indicate the call permission (public or private); s indicates that if the function is called, the signature of the function is identified.
  • -Extra = + Q: The ctags are required to perform the following operations. If a syntax element is a member of the class, the ctags records a row by default, ctags can be required to record a row of the same syntax element. This ensures that multiple functions with the same name in VIM can be distinguished by different paths.
3. common functions and shortcut keys

For details, see the tags help document of vim.

:help tags

The commands, shortcuts, and functions are described as follows:

  • CTRL +]: Jump to the definition of tag tagname
  • CTRL-W]: stag tagname opens and jumps to the definition in the new window. Execute tag tagname after split
  • CTRL + T Ctrl +. Similar to Ctrl + O, the difference is that the jump of Ctrl + O is not limited to the call tree consisting of Ctrl +.

For multiple matched tags (for example, method names declared or defined in. h and. cpp ):

  • : Ts [elect] lists all matched tags
  • : [Count] TP [revious] Jump to the previous count tag.
  • : [Count] tn [ext] jump to the next count tag.
4. VIM + ctags Configuration
Set tags = tags; #; cannot be omitted. If the current directory does not contain tags, search for it in the parent directory. Map <C-F12> :! Ctags-r -- C ++-kinds = + p -- fields = + IAS -- extra = + q. <CR>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.