Use of VIM cscope read source code

Source: Internet
Author: User
This is even worse. In the words of csloud itself-"you can think of it as a ctags that exceeds the frequency", its functions and power are evident, I will not elaborate on its introduction. If you have installed the help manual in Chinese described above, use the following command to see the Introduction:
: Help if_cscop.txt

Here is a simple excerpt for those who are still hesitating:
Cscope is a tool used in Interactive screens to help you:
* You can understand the working principle of a C program without turning it over in the thick program list.
* You do not need to be familiar with the entire program to know the location of the Code to be modified by the program bug.
* Check the effects of the proposed changes (such as adding an enumeration value.
* Verify that all source files have been modified as needed. For example, add a parameter to an existing function.
* Rename a global variable in all related source files.
* Change a constant to a preprocessing symbol at all related positions.

It is designed to answer the following questions:
* Where is this symbol used?
* Where is this defined?
* Where is this variable assigned a value?
* Where is the definition of the global symbol?
* Where is this function in the source file?
* Which functions call this function?
* What functions does this function call?
* Where does the information "out of space" come from?
* Where is the source file in the entire directory structure?
* Which files contain this header file?

Install cscope:
If your system has the cssag command, you can skip this section. If not, install one with me first.
Download a source package in the cscope home page: http://cscope.sourceforge.net, decompress the package, compile and install:

#./Configure
# Make
# Make install // root permission required

First in ~ /Add a sentence to vimrc:

: Set cscopequickfix = s-, C-, D-, I-, T-, e-

This is to set whether to use the quickfix window to display the csfix result. The usage will be described later.

Like ctags, to use its functions, you must first generate a cssag database for your code and run the following command in the project root directory:

$ CD/home/wooin/vim71/
$ Cs1_rbq
# Three files will be generated later
$ Ll cscope .*
-RW-r -- 1 wooin 1.1 m cs.pdf. In. Out
-RW-r -- 1 wooin 6.7 m cs.pdf. Out
-RW-r -- 1 wooin 5.1 m cs.pdf. Po. Out
# Open the file and start coding
$ CD SRC
$ VI main. c

After entering vim, the first thing is to import the generated cssag file to VIM. Use the following command:

: CS Add/home/wooin/vim71/csloud. Out/home/wooin/vim71

The preceding command is very important and must be fully written. You cannot write only the first half of the sentence:
: CS Add/home/wooin/vim71/cs.pdf. Out
Because the source code is a multi-level directory, if you write it like this, csflood cannot work in the source code in the subdirectory. Of course, it doesn't matter if your source code is in the same level directory. if you want to use csflood frequently, you can add the above sentence ~ /. Go to vimrc.

Let's drill down and look up the definition of the vim_strsave () function. Run the following command:

: CS find G vim_strsave

For example:

(--- Figure 8 ---)
Press enter to automatically jump to the definition of vim_strsave. at this point, you will certainly say that ctags can also do this, so the ctags mentioned below will not be able to do so. I want to find out where vim_strsave () has been called, run the following command:

: CS find C vim_strsave

Press enter and VIM will automatically jump to the first place that meets the requirements, and the command bar will display the number of results that meet the requirements ,:

(--- Figure 9 ---)
If you are not satisfied with the automatic jump location and want to see other results, you can use the following command to open the quickfix window:

: CW

:

(--- Figure 10 ---)
Then you can select pai_^

The main function of cssag is implemented through the same sub-command "find ".
Usage of "cs1_find:
CS find c | d | E | f | G | I | S | T name

0 or S Search for the C symbol (skip the annotation)
1 Or G Search for this definition
2 or d Find the function called by this function
3 or C Find the function that calls this function
4 or t Search for this string
6 or E Find the current egrep Mode
7 or F Find this file
8 or I Search for files containing this file

If you need to enter a long string of commands for each search, it is really annoying. Some shortcut keys are recommended in the cssag help manual. below is one of them, which is also used by me, add the following content ~ /. Vimrc, and restart VIM:

NMAP <c-_> S: CS find S <C-R> = expand ("<cword>") <CR>
NMAP <c-_> G: CS find G <C-R> = expand ("<cword>") <CR>
NMAP <c-_> C: CS find C <C-R> = expand ("<cword>") <CR>
NMAP <c-_> T: CS find t <C-R> = expand ("<cword>") <CR>
NMAP <c-_> E: CS find e <C-R> = expand ("<cword>") <CR>
NMAP <c-_> F: CS find F <C-R> = expand ("<cfile>") <CR>
NMAP <c-_> I: CS find I ^ <C-R >=expand ("<cfile>") <CR >$ <CR>
NMAP <c-_> D: CS find d <C-R> = expand ("<cword>") <CR>

When the cursor stops at a word you want to search for, pressing <c-_> G is to find the definition of the object. The same applies to other words.
One trick is to press this key combination. After you press <c-_>, You need to press the next key immediately. Otherwise, the screen will return to the nomal state as soon as it flashes.
<C-_> the G method is to press "Ctrl + Shift +-" first, and then quickly press "G"

This is a strange sentence:
NMAP <c-_> I: CS find I ^ <C-R >=expand ("<cfile>") <CR >$ <CR>
I cannot work in my vim, but I changed it:
NMAP <c-_> I: CS find I <C-R> = expand ("<cfile>") <CR>
I can work normally. I don't know why? Please let me know which of your friends knows.

You can use the help manual to learn more about other cssag functions.

Address: http://hi.baidu.com/bali5/blog/item/49ff3517c0997a01c83d6d4e.html

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.