Vim's tags module and ctags, vimctags
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>
After creating the tags file in vim, use ctrl + t or always show that the ctags stack is empty. Why? For VIMctags, the "startlist" in ctags-R is used in the folder. Even if the function is another file, the CTRL-] command will jump to the current cursor.
Vim + ctags: only delete the records of the current xxxc file in tags to solve the main problem. Split the tags distribution reasonably.
Solution 1:
The project is too big. Use the makefile file to update the tags. You should write the makefile file.
Write the tags dependency list in makefile.
Split the tags into modules. The following tags will be too fragmented as solution 2.
-------
Solution 2:
Tags files are generated in each folder in the project directory.
Enter the vim configuration file
Function Update_ctags ()
Let l: filepath = expand ("%: p: h ")
Let l: cmd = "! Cd ". l: filepath."; ctags-F *"
Silent execute l: cmd
Endfunc
Auto BufWritePost *. c, *. h call Update_ctags ()
"As long as the file is written, the directory tags of the file will be updated, and the tags in the subdirectory will be updated.
Assume that your_soft_src/the absolute path of the Project root directory
"Next, write the auto command to automatically set the tags list under the project directory.
Auto bufenter your_soft_src/* so your_soft_src/tags_setting.vim
Generate tags_setting.vim using linux commands
Echo-n "set tags + ="> your_soft_src/tags_setting.vim
Find your_soft_src-name tags | tr "\ n", "> your_soft_src/tags_setting.vim