Learn how to use cssag in VIM to read code efficiently during the NS2.

Source: Internet
Author: User
Tags egrep

First install ctags and cs.pdf:

$ Sudo apt-Get install ctags cs.pdf

 

Then, execute the script in the folder where you want to create an index to generate the required out file. The script is as follows:
#! /Bin/sh <br/> Find. -Name "*. H "-o-name "*. TCL "-o-name "*. C "-o-name "*. cc "> cscope. files <br/> # If you need to add a special file format, follow the preceding format. <br/> # Find is not recommended. -Type F> cscope. files and then cs1_bq, because an error may be reported <br/> cs1_bkq-I cs1. files <br/> ctags-R

 

VIM + ctags/cs.pdf

 


1. Use VIM + ctags

A first, we must create one or more tags files for the original code to be read,


Use the ctags command in shell to create a tags for a single file as follows:
$ Ctags filename. c

To create a tags for all files in the same directory:
$ Ctags-R

In this case, open the source file in the directory where the tags file is located, and VIM will automatically call the tags file.
If the tags file is not in the current directory, use the following command in command mode to set the Tag file.
: Set tag = tag_file_path

However, for me, tags are all under the current directory, so I am used ~ /. Add the following to vimrc:
: Set tags = $ PWD/tags

B. to jump to the definition of a function under vim, use the following command in command mode:

: Tag fuction_name
This command will take you to the definition of the fuction_name function.
This function is very useful and has never been noticed before.

C. In addition, the CTRL +] command uses the words under the current cursor as the Tag Name and jumps directly.
Press Ctrl + T to return to the previous tag. You can add a number before Ctrl + T to jump back.
Number of layers.

D. use Ctrl + GTO display the file name being edited and the row number.
If the source file layout is messy, you can use the command Gg = g to format the entire source file.


2. cscope

Before using cssag, You need to form a database.
A generates the index file:


Cssag options for generating index files:
-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 cs.pdf. Files, add this option
Where to find the source file list. "-" Indicates that the file list is obtained by 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 do not need to convert it to your database.
The directory where the file is located can also be used.

If your source code only contains. C and. H files, you can directly use
$ Cs1_rbq

Before using cssag, you need to create a database. You can use cssag-indexer (if multiple
Directory, you can use the-r option). It will generate a file for csprogram. Files in the current directory.
The file contains all the files for generating the index for cssag, because cssag-indexer does not automatically find. cpp,. s
Therefore, use find to generate the cssag. Files file:
$ Find./-name "*. c"-or-name "*. H"-or-name "*. cpp"> cs.pdf. Files

The preceding command lists all. C,. H,. cpp files in the current directory and writes them to the cs.pdf. Files file.
Then use cs1_rbq to generate index reference.
$ Cs1_rbq

General Usage:
$ Find. /-name "*. C "-or-name "*. H "-or-name "*. CPP "-or-name "*. s "| cs1_rbq

B. Then you can use Vim to open a file to browse and edit the code.

The best way to view csflood usage is to input the following in VIM:
: CS Help

Here is a brief explanation:
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

For example, the most common query function calls the function func ():
: Cs f c func
Or
: CS find C func
The last two images:
This is automatic completion:

Below is the function parameter prompt:

Some friends discussed case-insensitive:
Case sensitivity is ignored here:

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.