Vim+cscope Easy Tutorial

Source: Internet
Author: User
Tags egrep

Cscope, with its pure UNIX pedigree, was originally developed by Bell Labs for the PDP-11 computer and later became part of the commercial, T/t UNIX distribution. It was not until April 2000 that the tool was released by SCO in the BSD license open source.

Cscope's homepage is in http://cscope.sourceforge.net/, if you don't have cscope on your computer, you can download it here, and at the time of writing, the latest version of it is 15.8b. Mac can be installed with the homebrew one click.

1, the use of cscope is very simple, first need to generate a cscope database for your code. Run the root directory of your project:

Cscope-rbq

2. This command generates three files: Cscope.out, Cscope.in.out, Cscope.po.out. Where Cscope.out is the basic symbol index, the latter two files are generated using the "-q" option, which speeds up the indexing speed of the cscope.

3, by default, cscope after the database is generated into its own query interface, we generally do not use this interface, so the "-B" option is used. If you have entered this interface, press ctrl-d to exit.

4. Cscope in the build database, header files that are not found in your project directory are automatically looked up in the/usr/include directory. If you want to prevent it from doing so, use the "-k" option.

5,-R indicates the index subdirectory. R is the first character shorthand for recursion.

Use Cscope in vim:

1. To use the Cscope function in vim, you need to select "+cscope" when compiling vim. Vim's Cscope interface first invokes the Cscope command-line interface and then analyzes its output to find a match to display to the user.

2, the use of cscope in Vim is very simple, first call the "cscope Add" command to add a cscope database, and then you can call the "cscope find" command to find.

3,vim support 8 kinds of cscope query function, as follows:

    • S: Find the C language symbol, that is, find the function name, macro, enumeration value and other occurrences of the place
    • G: Find the location defined by functions, macros, enumerations, and similar functions provided by ctags
    • D: Find functions called by this function
    • C: Find functions that call this function
    • T: finds the specified string
    • E: Find Egrep mode, equivalent to Egrep function, but find much faster
    • F: Find and open files, like Vim's find function
    • I: Find files that contain this file

4, for example, we would like to find in the source code of VIM 7.0 call Do_cscope () function function, we can enter: ": CS Find C Do_cscope", enter after found no matching function, there may be no function call Do_cscope (). We then enter ": CS Find S Do_cscope" to find out where the C symbol appears, and now vim lists all the locations where the symbol appears.

5, we can also do string lookup, it will be double quotation marks or single quotes in the contents of the search. You can also enter a regular expression, which is similar to the functionality of the EGREP program, but it is much faster to find in a cross-indexed database.

6, VIM provides some options to adjust its cscope function:

    • The CSCOPEPRG option is used to set the location of the Cscope program.
    • Cscopequickfix set whether to use the Quickfix window to display the results of cscope, details please ": Help Cscopequickfix";
    • If you want VIM to search both the tag file and the Cscope database, set the cscopetag option;
    • The Cscopetagorder option determines whether to find the tag file first or to find the Cscope database first. Set to 0 to find the Cscope database first, set to 1 to find the tag file first. I usually set to 1, because the result found in the tag file will be the best match listed in the first place.

7. The VIM manual gives the recommended method for using Cscope, using the command ": Help Cscope-suggestions" to view.

8. Using Cscope on large projects (example:the Linux kernel): http://cscope.sourceforge.net/large_projects.html

9. The Vim+cscope tutorial:http://cscope.sourceforge.net/cscope_vim_tutorial.html

Vim+cscope Easy Tutorial

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.