[Vim] cssag installation basics and usage

Source: Internet
Author: User
Tags egrep
Install
  • In centos, we can directly use the yum command for installation.
Overall steps
  • Install cscope
  • Configure the vim configuration file
  • Generate a cssag. Out File
  • Use the cssag command to perform operations
Cssag Installation
  • Download on the cssag home page: http://cscope.sourceforge.net
  • Cent OS users can use the yum command to install
    • yum install cscope
  • Use configure configuration items during installation./configure --with-flex(Note: If the platform is Linux, it is best to include the -- with-Flex option)
  • In addition: To support csflood in Vim, you must configure the configure file of VIM before compiling vim and add an option../configure --enable-cscope
To generate a cssag File
  • Command:cscope -Rbkq

    • RIndicates that all files in the subdirectories are indexed.
    • bIndicatescscopeInstead of starting the built-in user interface, you only need to create a symbolic database.
    • qGeneratecscope.in.outAndcscope.po.outFile to speed upcscopeIndex speed
    • kWhen generating index files, do not search/usr/includeDirectory
  • The C and C ++ Languages differ when generating cssag files. For specific differences, refer to the online documents.

  • When there is a C ++ file, we need to convert it into a cssag file and then use this file to perform cssag operations. Otherwise, the generated cssag. File file is inaccurate.
  • After the cssag command is executed, three files are generated. The cssag. Out file is an index, and the other two files are used to accelerate the index speed.
Searches for files of the specified type in a directory.
  • Find all c files:find . -name ‘*.c‘
  • Other types, and so on
Configure the vim configuration file
"Cscope set cscopequickfix = s-, C-, D-, I-, T-, e-
  • As mentioned in this articleChange the path to your own source code path. You need to confirm how to set this.
  • Cscopequickfix indicates the configuration associated with quickfix.
Cssag Operation Command
  • :cs f g bootYou can view the definition of the function boot. Enter:
  • :cs f c bootYou can view where the boot () function is called. Is it convenient? However, you can search more conveniently and use the shortcut key! To use the shortcut key, we also need to configure it. Add the following statement to the vimrc file:
  • :cs find s---- Search for the C language symbol, that is, find the place where the function name, Macro, and enumeration value appear
  • :cs find g---- Find the locations defined by functions, macros, and enumeration, similar to the functions provided by ctags.
  • :cs find d---- Find the function called by this function
  • :cs find c---- Find the function that calls this function
  • :cs find t: ---- Search for the specified string
  • :cs find e---- Find the egrep mode, which is equivalent to the egrep function, but the search speed is much faster
  • :cs find f---- Find and open the file, similar to the find function of VIM
  • :cs find i---- Search for the text that contains this file
Define the cscope shortcut
  • nmap s :cs find s =expand("") :cw"Search statement
  • nmap g :cs find g =expand("") :cw"Search Definition
  • nmap c :cs find c =expand("") :cw"Query call
  • nmap t :cs find t =expand("") :cw"Find the specified string
  • nmap e :cs find e =expand("") :cw"The egrep mode is equivalent to the egrep function, but the search speed is much faster.
  • nmap f :cs find f =expand("") :cw"Searching for files
  • nmap i :cs find i ^=expand("")$ :cw"Search for files containing this file
  • nmap d :cs find d =expand("") :cw"Find the function called by this function
    In addition, a cscope_map.vim file can be downloaded. After downloading, we can copy the content from if has ("cshas") to endif to/etc/vimrc.

The shortcut key above is used to position the cursor to the variable, function name, or macro definition name you are looking. PressCtrl+/After the function is released, press the corresponding key. For example, if you press G, you can find the definition of the function or variable. If you press C, you can find the place where the function is called. Powerful functions.

Briefly explain the above shortcut key ing

For example:nmap <C-/>s :cs find s <C-R>=expand("<cword>")<CR><CR>

  • nmapIn the normal mode of VIM, that is, compared with the edit module and visual mode, the following modes are used:
  • :mapCommon, visual, and operator wait Modes
  • :vmapVisual Mode
  • :omapOperator wait Mode
  • :map!Insert and command line modes
  • :imapInsert mode
  • :cmapCommand Line Mode
  • <C-/>CTRL +/
  • <C-R>=expand("cword")The overall goal is to get the variable or function under the cursor. Cword: cursor word. For example, cfile indicates the name of the file where the cursor is located.
  • <CR><CR>Press enter.
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.