With VIM + cssag/ctags, You can implement the source insight function and conveniently view the source code for analysis.
Key words: vim, cssag, ctags, tags 1. check whether Vim supports cscope $ Vim -- version | grep cs1_2. compile Vim (-- enable-cscope) that supports cssag) # Use = "bash-completion cscope NLS Perl Python-ACL-GPM-minimal-ruby-vim-pager-vim-with-X" emerge Vim # emerge-AV Dev-util/ cssag # emerge-AV Dev-util/ctags $ which csags $ which ctags 3. view help $ man csags $ man ctags: Help csloud (Vim command) refer to [1] http://vimcdoc.sourceforge.ne T/doc/if_cscop.html 4. the current directory has main. c. cstest is called. print () in C. This function is in cstest. h.
Use the following command to generate a symbolic index file for the Code:
$ Cscope-rbkq
This command generates three files: csexample. Out, csexample. In. Out, csexample. Po. Out.Cssag. out is the basic symbolic index, and the last two files are generated using the "-Q" option, which can speed up the cssag index. The parameter Meanings of the preceding command are as follows:-R: When an index file is generated, search for the code-B in the subdirectory tree: only the index file is generated and the cssag interface is not displayed.
-D: only call out the cssag GUI, not with the new cssag. out-K: when generating the index file, do not search for the/usr/include directory-Q: Generate cscope. in. out and cscope. po. out file, accelerate the indexing speed of cssag-I: If the file name to save the file list is not cssag. files, you need to add this option to tell cscope where to find the source file list. You can use "-" to obtain the file list from the standard input. -I dir: in the directory specified by the-I option, find the header file-u: scan all files and regenerate the cross-index file-C: Ignore the case-P path: in this way, you do not need to switch to the directory where your database file is located or use it. By default, cssag will enter its own query interface after the database is generated. This interface is generally not used, so the "-B" option is used. If you have already entered this interface, press the CTRL-D to exit. Next, you can browse the code $ Vim main in Vim. c. Add the symbol index library in the command status in VIM: cs1_add cs1. then, you can view the corresponding function definition or file, and press Ctrl + T to return.: Cs1_find g print: cs1_find F cstest. h # Note # The generated cs1_out and tags files must be in the folder where Vim is opened. Otherwise, VIM cannot find the relevant symbol information. 5. Create a shortcut to add the following content ~ /. In vimrc, VIM automatically loads the symbol index cs1_out in the current directory. You can use Ctrl + T or Ctrl +. """""""""""""""""""""""""""""""""""""""" "Cscope setting if has (" CSAs ") set csprg =/usr/bin/cssag "specifies the command set CSTO = 1 used to execute cssag" first searches for the tags Tag file, and then searches for cssag database set CST "to use |: cstag | (: CS find G), instead of the default: tag set nocsverb "does not show whether the database is successfully added" add any database in current directory if filereadable ("csable. out ") CS add cscope. out "adding a cssag database endif set csverb": whether the database is added successfully or not. endif NMAP <[email protec Ted]> S: CS find S <C-R> = expand ("<cword>") <CR> NMAP <[email protected]> G: CS find G <C-R> = expand ("<cword>") <CR> NMAP <[email protected]> C: CS find C <C-R> = expand ("<cword>") <CR> NMAP <[email protected]> T: CS find t <C-R> = expand ("<cword>") <CR> NMAP <[email protected]> E: CS find e <C-R> = expand ("<cword>") <CR> NMAP <[email protected]> F: CS find F <C-R> = expand ("<cfile>") <CR> NMAP <[emai L protected]> I: CS find I ^ <C-R >=expand ("<cfile>") <CR >$ <CR> NMAP <[email protected]> D: CS find d <C-R> = expand ("<cword> ") <CR> """""""""""""""""""""""""""""""""" "in which <[email protected]> G is the first press [email protected, then press G. The function is to view the definition of the symbol where the current cursor is located. 6. After reading the code to add the cssag symbol index database, VIM can call the "cssag find" command for search. Vim supports the query functions of eight CSBs. For example, if you want to find the function that calls the work () function in the code, you can enter ": CS find C work" in the vim command state and press Enter. You can also perform string search, which searches for the content enclosed by double quotation marks or single quotation marks. You can also enter a regular expression, which is similar to the function of the egrep program.: CS Help (query under Vim command)
S: Find the C language symbol, that is, find the place where the function name, Macro, enumerated value, and so on appear
G: Find the locations defined by functions, macros, and enumeration, similar to the functions provided by ctags.
D: Find the function called by this function.
C: Find the function that calls this function.
T: Find the specified string
E: Find the egrep mode, which is equivalent to the egrep function, but the search speed is much faster.
F: Find and open the file, similar to the find function of vim.
I: Find the file that contains this file7. view and read c ++ code [3] cscope only parse C files by default (. C and. h), Lex file (. l) and YACC files (. y), although it can also support C ++ and Java, but it will skip the C ++ and Java suffix files during directory scanning. To parse C ++ or java files in cssag, save the names and paths of these files in a file named cssag. Files. When cssag finds that cssag. files exists in the current directory, it will generate an index database for all files listed in cssag. Files. The following Command finds all the Suffixes in the current directory and subdirectory ". H ",". C "," cc "and ". CPP file, and redirect the search result to the file cs.pdf. files. Then cssag generates a symbolic index file based on all files in cssag. Files. The last command uses the ctags command to generate a tags file and run the ": Help tags" command in VIM to query its usage. It can be used with cscope. $ Find. -Name "*. H "-o-name "*. C "-o-name "*. cc "-o "*. CPP "> cscope. files $ cscope-bkq-I cscope. files $ ctags-R 8. use the tags search symbol in VIM to view the ctags help $ man ctags: Help ctags (Vim command): Help tags (Vim command)
Run the ctags-R command in the root directory of the source code to generate a Tag file for the program's source code. The-r option indicates recursive operation and a Tag file is generated for the subdirectory. Vim uses the generated Tag file to perform corresponding searches and switch back and forth between C language elements of different files.
$ Ctags-RA) Use ": Tag XXX" in VIM to jump to function or data structure XXX. When using the tag command, you can use the tab key to perform matching search and continue to switch down by pressing the tab key. When a function has multiple definitions: The tag jumps to the first definition, and the current file: tnext jumps to the first: tfirst to the previous count: [count] tprevious jumps to the next count: [count] tnext to the last one: tlast. You can also select: tselect tagname among all tagnames. If you want to skip to the identifier containing the block ": tag/block "and then use the tab key for selection. Here '/' indicates that Vim 'block' is a statement block tag.
B) use the "Ctrl +]" shortcut to jump to the definition of the Function Identifier where the cursor is located.
C) use "Ctrl + T" to return to the upper layer.If you want to select an identifier starting with write _, tselect/^ write _ here, '^' indicates the start. Similarly, '$' indicates the end. D. Run Vim in the directory where the "tags" file is located. Otherwise, run the ": Set tags = xxx" command to set the path of the "tags" file, in this way, VIM can find the "tags" file (we have already set "set tags = tags;", which can also be used in sub-Directories ). E) shortcut keys for moving the cursor in the function: [{go to the previous "{"}] In the first column to the next "{" {go to the previous blank line} in the first column to the current empty line GD definition of the local variable pointed by the cursor * to the next occurrence of the word pointed by the current cursor # To the last occurrence of the word pointed by the current cursor 9. the taglist plug-in uses [4]. This plug-in can display the macros, global variables, and functions in the current file in the symbol window like source insight. Click the above tag with the mouse, to the position defined by the tag. You can sort the tag in alphabetical order, the class or scope to which the tag belongs, and the position where the tag appears in the file. If you switch to another file, the tag in this file is updated in the symbol window. Taglist depends on ctags. To use the taglist plug-in, you must meet the following requirements: 1 ). enable the vim file type automatic detection function; 2 ). the exuberant ctags tool is installed in the system, and the taglist tool can be found (because the taglist needs to be called to generate the Tag file); 3 ). your Vim supports system () calls. Install the taglist plugin # emerge-AV app-Vim/taglist to view help: Help helptags: Help taglist-intro. Open the tag window: tlisttoggle. configure the following in vimrc """""""""""""""""""""""""""""""""""" "ctags settingset tags =. /tags ,. /.. /tags ,. /*/tags; "tag list (ctags) filetype o N "File Type Automatic Detection If mysys () =" Windows "" sets the location of the ctags program in Windows system let tlist_ctags_cmd = 'ctags 'elseif mysys () = "Linux" ": Set the ctags program location in Linux. Let tlist_ctags_cmd = '/usr/bin/ctags' endif let tlist_show_one_file = 1" the tag of multiple files is not displayed at the same time, show only the current file's let tlist_exit_onlywindow = 1 "if the taglist window is the last window, exit vimlet tlist_use_right_window = 1" display the taglist window map in the right window <silent> <F8>: tlisttoggle <CR> "Open the tags window by ing the F8 key """""""""""" """""""""""""""""""""""""""""""""""""""" "10. create an index database and view the kernel source code [5] [email protected] ~ /Git/kernel/linux-2.6.30.5 $ make cs1_gen csted [email protected] ~ /Git/kernel/linux-2.6.30.5 $ make tags Gen tags [email protected] ~ /Git/kernel/linux-2.6.30.5 $ ls tags-L-RW-r -- 1 liuby 89648962 03-12 tags [email protected] ~ /Git/kernel/linux-2.6.30.5 $ ls cscope. *-L-RW-r -- 1 liuby 403901 03-12 cscope. files-RW-r -- 1 liuby 182562815 03-12 cscope. out-RW-r -- 1 liuby 23011328 03-12 cscope. out. in-RW-r -- 1 liuby 133571208 03-12 cscope. out. po
VIM + ctags + csags usage