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>