Use VIM + cssag + ctags to view code

Source: Internet
Author: User

In Linux, we cannot easily view the code. We don't know how to use many tools. Below is a summary of my VIM + cssag + ctags environment:

1. Vim

(1) Check whether Vim supports csflood.

# Vim -- version | grep cscope

+ Cryptv + cs1_+ cursorshape + dialog_con_gui + diff + digraphs + DND-ebcdic

If not, recompile Vim; otherwise, skip to (3)

(2) Compile Vim. The source code I use is vim72.

# Vim vim72/src/makefile

# Conf_opt_cs1_= -- enable-cs1 _

Change

Conf_opt_cs1_= -- enable-cs1 _

During compilation and installation, use the Linux trilogy:

#./Configure

# Make

# Make install

# Vim -- version | grep cscope

+ Cryptv + cs1_+ cursorshape + dialog_con_gui + diff + digraphs + DND-ebcdic

(3) install cssag and ctags

A. http://cscope.sourceforge.net/(cscope source code download)

 

B. http://ctags.sourceforge.net/(ctags source code download)

 

Install logtail using Linux installation Trilogy

 

(4) modification to the. vimrc File

A. http://cscope.sourceforge.net/here there is a cscope_map.vim file, put the IF has ("CSAs") inside to endif
Copy to. vimrc. In this way, you can use the shortcut key to replace commands such as "cs1_find C ***", which is very useful.

B. Add set tags =./tags, tags,/usr/include/tags to. vimrc.

 

 

(5) application. The theory is not mentioned much. Just give an example:

Under the directory of your source code

# Find. -Name "*. H "-o-name "*. C "-o-name "*. cc "> cscope. files (add the source files of the local directory and subdirectory)

# Find .. /common "*. H "-o-name "*. C "-o-name "*. cc "> cscope. files (add files from other directories)

 

# Cscope-bkq-I cscope. Files

# Ctags-R

 

Note:

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.

Next:

# Vim qljt. C open the file and execute the VI command

: Cscope add cscope. Out

Test:

Use "Ctrl +]" to jump to the definition of the function, and press "Ctrl +/" to jump to the place where the function is called.

 

 

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.