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
- 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
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 boot
You can view the definition of the function boot. Enter:
:cs f c boot
You 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>
nmap
In the normal mode of VIM, that is, compared with the edit module and visual mode, the following modes are used:
:map
Common, visual, and operator wait Modes
:vmap
Visual Mode
:omap
Operator wait Mode
:map!
Insert and command line modes
:imap
Insert mode
:cmap
Command 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.