VIM + ctags + cs.pdf

Source: Internet
Author: User
Tags egrep

Ctags Installation

Ctags can create source tree indexesProgramDevelopers can quickly locate functions, variables, macro definitions, and other locations during programming to view the prototype.
The following describes how to download, install, and configure ctags in Ubuntu:
Download and install ctags, and enter the command on the terminal
Sudo apt-Get install ctags
Create source code indexes. For example, I often need to check the Linux kernel.CodeAnd put the code in the/home/hsf-951/ARM/linux-2.6.12 directory


After the terminal enters the directory, enter the command ctags-R * and you will find an additional tags file, which is the index file.
Register the index file tags path with vim, and enter gedit/etc/Vim/vimrc on the terminal as the root user.
Add a line at the end of the file to open (of course, the specific path is based on your own situation)
Set tags =/home/users/ARM/linux-2.6.12/tags
Then close the terminal and re-open it. You can use Vim to view the Linux function prototype anywhere.

 

Taglist plugin

Those who have used source insight must remember this function: Si can display the macros, global variables, functions, and other tags in the current file in the symbol window, and 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.

In vim, The taglist plug-in Implements similar functions. Some functions are weaker than Si, and some functions are stronger than SI. In addition, the taglist plug-in is still being improved!

To use taglist plugin, you must meet the following requirements:

Enable the file type automatic detection function of VIM:Filetype on

Installed in the systemExuberant ctagsTool, and the taglist plugin can find this tool (because the taglist needs to be called to generate the Tag file)

 Your Vim supports system () calls.

 

Taglist Installation

1. Create. Vim in the user's home directory

[Atom @ localhost ~] $ Mkdir. Vim

2.decompress taglist_45.zip to the. Vim directory

[Atom @ localhost ~] $ Unzip taglist_45.zip-D. Vim

The decompressed directory structure is as follows:

[Atom @ localhost ~] $ LS-r taglist

Taglist:
Doc plugin

 

Taglist/DOC:
Taglist.txt

 

Taglist/Plugin:
Taglist. Vim

3. Install taglist
[Root @ localhost atom] # cp/taglist/doc/taglist.txt/usr/share/Vim/vim71/doc/
[Root @ localhost atom] # cp/taglist/plugin/taglist. Vim/usr/share/Vim/vim71/plugin/

4. Generate help labels
Enter the vim Doc path.
CD/usr/share/Vim/vim71/doc

Start vim and enter
: Helptags. (. indicates the current directory. You can also start Vim in any directory, as long as you specify: helptags usr/share/Vim/vim71/doc /)

After the Help Tag is generated, you can use the following command to view the taglist help
: Help taglist.txt

Now we can try to open the taglist in vim and enter the command
: Tlisttoggle to open and close the taglist window. (The command can be abbreviated as tlist)

 

Command usage

CTRL +]: Jump to the Function Definition place where the function is called

CTRL + T: Return to the directory structure extracted from the previous search as follows:

LinuxSource codeThe make command is provided to create a cssag index file and a tags file.   I. Software Installation First install cssag, ctags:

Click (Here) Fold or open

    1. Sudo apt-Get install csloud, ctags

 

You can also install the ctags package:
Http://ctags.sourceforge.net/ You can use: ctags-version to check whether the current ctags version is Emacs. If Emacs is installed, you must use the ctags address above. Vim does not support the ctags of Emacs. Therefore, you must download and install the ctags. (This is a previous version. Now you can install it directly using apt-Get install) Run the following command in the directory where the source file is downloaded:

Click (Here) Fold or open

    1. Helight @ helight-desktop :~ /Desktop/ctags-5.7 $./configure
    2. Helight @ helight-desktop :~ // Desktop/ctags-5.7 $ make
You can generate the ctags file and save it to the "/usr/bin/" directory.   Ii. generate an index fileUnder the source code directory Use the following two commands to generate the cssag index file and tags file.

Click (Here) Fold or open

    1. Helight @ helight-desktop :~ /Downloads/linux-2.6.26 $ make cscope
    2. Filelst cscope. Files
    3. Make cscope. Out
    4. Helight @ helight-desktop :~ /Downloads/linux-2.6.26 $ make tags
    5. Make tags
    6. Helight @ helight-desktop :~ /Downloads/linux-2.6.26 $ ls tags-l
    7. -RW-r-1 helight FTP 69274841 tags
    8. Helight @ helight-desktop :~ /Downloads/linux-2.6.26 $ ls cscope. *-l
    9. -RW-r-1 helight FTP 23814144 2008-09-25 cs.pdf. In. Out
    10. -RW-r-1 helight FTP 609665 cs.pdf. List
    11. -RW-r-1 helight FTP 174470617 2008-09-25 cs.pdf. Out
    12. -RW-r-1 helight FTP 124973256 2008-09-25 cs.pdf. Po. Out
  3. index files are generated in common source files. For ease of use, Write the following script to update the index files of cssag and ctags:

Click (Here) Fold or open

    1. #! /Bin/sh
    2. Find.-Name "*. H"-o-name "*. c"-o-name "*. cc"> cscope. Files
    3. Cscope-bkq-I cscope. Files
    4. Ctags-R
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.

This script first uses the find command to find all the Suffixes in the current directory and subdirectory ". H ",". C "and ". C "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. The command parameters used above have the following meanings:
-R: Search for the code in the subdirectory tree when generating the index file
-B: Only the index file is generated, and the cssag interface is not displayed.
-Q: generate the cssag. In. Out and cssag. Po. out files to speed up the cssag index.
-K: when the index file is generated, the/usr/include directory is not searched.
-I: If the file name for saving the file list is not cssag. files, you need to add this option to tell cssag where to find the source file list. You can use "-" to obtain the file list from the standard input.
-I dir: Find the header file in the directory specified by the-I option.
-U: scan all files and regenerate the cross-index file.
-C: Case Insensitive during search
-P path: the path added before the file in the relative path. In this way, you can use it without switching to the directory where your database file is located.   4. Search Using cssag in VIM, Load the cssag. Out File
It is very easy to use cssag in Vim. First, call the "cssag Add" command to add a cssag database, and then you can call the "cssag find" command for search. Vim supports eight types of cscope query functions. For example, if we want to find the function that calls the work () function in the code, we can enter ": CS find C work ", after you press enter, you will find that the matching function is not found, and the function may not call work (). Enter ": CS find s work" to find the position where the symbol appears. Now Vim lists all the positions where the symbol appears. We can also search for strings, which are 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.
Open Vim in the source code directory. To use cscope for search, you must load the cscope. Out file. Run the following command in the vim command line:
Click ( Here ) Fold or open
    1. : CS add cscope. Out
Run the following command in the vim command line:

Click (Here) Fold or open

    1. : CS Help
    2. Cs1_commands:
    3. Add: Add a new database (usage: Add file | dir [pre-path] [flags])
    4. Find: Query for a pattern (usage: Find c | d | E | f | G | I | S | T name)
    5. C: Find functions calling this function D: Find functions called by this function
    6. E: Find This egrep Pattern
    7. F: Find this file G: Find This definition
    8. I: Find Files # Including this file S: Find This C symbol
    9. T: Find assignments to help: Show this message (usage: Help)
    10. Kill: Kill A connection (usage: Kill #)
    11. Reset: reinit all connections (usage: reset)
    12. Show: show connections (usage: Show)
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 text that contains this file   2. Use cscope to find the do_fork Function Definition:
Run the following command in the vim command line:

Click (Here) Fold or open

: Cs f g do_fork   5. Use the tags search symbol in VIM: Run the following command in the vim command line:

Click (Here) Fold or open

    1. : Tag xxx
You can find the function, data structure, or function xxx you are looking.
For other tags usage, run the ": Help tags" command in VIM to query.   6. Other commands: CTRL +]: Jump to the Function Definition place where the function is called.
CTRL + T: return the last lookup location   7. Special notes: The generated cscope. Out and tags files must be in the folder where Vim is located. Otherwise, VIM cannot find the relevant symbol information.   Ctags has been used in VIM for a while, but it is really inadequate. Ctags can only find the place where the function is defined based on the place where the function is called. It cannot find the places where the function is called.
This function. So I learned cscope again. Cssag said on its home page that it had uncertain UNIX lineage, which had been developed in Bell Labs as early as the age of PDP-11. My
Linux is suse10.0, and the system comes with cssag software.
I. Set
Http://cscope.sourceforge.net/cscope_maps.vim
Save as file ~ /. Vim/plugin/cscope_maps.vim
2. Because cssag uses "Ctrl + space" as the ing key, but this will call up the input method ~ Replace/. Vim/plugin/cscope_maps.vim with (or your favorite shortcut key that you have not mapped)
3. Go to the C language source code directory and create a symbol table:
Mishuang @ MSH :~ /Linux/linux0.11/source-0.11> cs1_r
After the CTR-D exits, the current directory will have one more file cs1_out, which is much larger than the tags.
Iv. User Guide
1) use the following command to directly enter the main function definition. If there are multiple, enter the index number and press Enter.
Mishuang @ MSH :~ /Linux/linux0.11/source-0.11> vi-t Main
2) move the cursor over a function or variable and press Ctrl +] To jump directly to the place where the function is defined.
3) move the cursor over a function or variable, press Ctrl + \, and then input S. All the places where the function is called and defined will appear. Enter the index number, press enter.
4) move the cursor over a function or variable, and then input "S" to display all the places where the function is called and defined. Enter the index number, after you press enter, it will be displayed horizontally in another window.
5) move the cursor over a function or variable, and then input "S" to display all the places where the function is called and defined. Enter the index number, after you press enter, it is displayed vertically in another window.
6) Ctrl + t return to the place before the original jump, and press ''twice in a row to go back.
Appendix:
Vim split window operations
: Split horizontal (up/down) Split Window
: Vsplit or CTRL-W v vertical (left) Split Window
: New horizontal split window to create an empty file
: Vnew Vertical Split Window, create an empty file
Vim Multi-Window operation command
: Qall exit all windows
: Wall: Save all windows
: Wqall or: xall save and exit all windows
: Wqall! Or: xall! Save and exit all windows. If some files are read-only, you do not need to set the write permission first.
: Qall! Force exit all windows
CTRL-W W move between windows
CTRL-W o close all other windows

After we load CTAG + taglist + winmanager in Vim

When we associate a function or variable definition, the same name is often defined in multiple places, and the correct definition needs to be located.

: Ts or tselect have definitions in the same place

: Tn or tnext.

: TP searches for the previous place.

: Tfirst to the first match

: Tlast to the last match

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.