Linux Core Reading Tools Vim+ctags+cscope+taglist

Source: Internet
Author: User
Tags prototype definition egrep

today . describes the kernel reading configuration of vim+ctags+cscope+taglist.

When used, I believe most people will abandon the previous eclipse (I am a living example). Let's start by looking at what the implementation interface looks like:

Let's take a look at how it's achieved. Here is mainly through the vim-based several plug-ins built, that is, our title of the Ctags+cscope+taglist. Their respective functions are as follows:

Ctags: Realization of jump between functions, definition of high-speed lookup function

TagList: A plugin based on Ctags and Vim, mainly for the right side of the folder navigation

Cscope: Very powerful source code search tool, able to find the definition of functions, calls, etc.

Let's build it here.

First, the construction and use of ctags

First or download the source code package: http://nchc.dl.sourceforge.net/project/ctags/ctags/5.8/ ctags-5.8.tar.gz

tar zxvfctags-5.8.tar.gz

CD ctags-5.8

./configure

make && make install

after compilation is complete. We do the ctags configuration. Go to our source Code storage folder/home/sleipnir/linuxcore/linux-2.6.32.61/

This assumes that a troublesome friend is able to write the set command into the ~/.VIMRC.

Second, the construction and use of taglist

TagList is a ctags extension, so you need to determine the installation of ctags before installing. We have shown on the above, first download a source code from the following URL:

http://www.vim.org/scripts/download_script.php?src_id=7701
After the download is complete. Creates a new hidden file in the current ~/folder. Vim. That is, the ~/.vim folder. Then put the package we downloaded to unzip. It's over. The file structure after decompression, such as the following

~/.vim/doc/taglist.txt

~/.vim/plugin/taglist.txt

Finally, a little bit of optimization is to stick the following code in the ~/.VIMRC file.

"Press F8button. The TagList form appears on the left side of the form, like the WorkPace on the left side of the VC nnoremap <silent> <F8>:tlisttoggle<cr><cr> ": Tlist call TagList Let tlist_show_one_file=0 "only show tags for the current file let Tlist_exit_onlywindow=1 "assume that the TagList form is the last form to exit Vim Let tlist_use_right_window=1 "appears in the right side of the form Let tlist_file_fold_auto_close=1 "self-folding voluntarilyUsage such as the following:

After entering vim, press F8 to start TagList, and in the TagList form, you can also use the following shortcut keys:

<CR> jumps to the position defined by the tag under the cursor. Double-click the tag function with the mouse as well
o display the cursor under tag in a newly opened form
<Space> display the prototype definition of tag under cursor
U update tag in the TagList form
s change sort mode, toggle between sort by name and sort by order
x taglist form zooms in and out to make it easier to see longer tags
+ Open a folding, with Zo
-Fold the tag together with ZC
* Open all folds, with ZR
= Fold all tags together with ZM
[[Skip to previous file]
]] to skip to the next file
Q Close TagList Form
<F1> Show Help

Third, the construction and use of cscope

Cscope can be said to be Ctags's enhanced version. Since Ctags is only able to jump to the definition of a function, Cscops can also get information about the location of the function call and so on.

First, download the installation package:

http://sourceforge.net/projects/cscope/files/
After the download, we still unzip,./configure, make && make install.

All right. The following is a cscope configuration.

First of all. We enter CSCOPE-RBKQ < return in the folder below >

explain the number of references: R means that the files in all subfolders are also indexed B to indicate that the cscope does not start with the user interface that comes with it. Instead of just building the symbol database Q generate cscope.in.out and cscope.po.out files, speed up the index speed of cscope K when you generate an index file, the/usr/include folder is not searched Several files are then generated in the current folder. cscope.in.out and Cscope.po.out files, cscope.out
then &NBSP;~/.VIMRC adds the following code to the file:  
if filereadable (" Cscope.out ")  
    cs Add cscope.out  
endif  
This allows you to use cscope every time you turn on vim.
Usage:
-----The following is the reprinted .  author (Wu Yin)
--------http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx
Cscope's main function is to use the same subcommand "find" to implement the
Cscope Find method:
Cs Find c|d|e|f|g|i|s|t name
0 or S find this C symbol (can skip gaze)
1 or G find this definition
2 or D
3 or C Find functions that call this function
4 or T find this string
6 or e find this egrep mode
7 or F find this file
8 or I Find files that include this file

It's really annoying to have to enter a long list of commands every time you find it. Cscope's help manual recommended some of the use of shortcut keys, the following is a group, also I use, add the following content to the ~/.VIMRC, and restart Vim:
nmap <c-_>s:cs find S <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>g:cs Find G <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>c:cs Find C <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>t:cs Find T <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>e:cs Find e <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>f:cs find F <c-r>=expand ("<cfile>") <CR><CR>
Nmap <c-_>i:cs Find I ^<c-r>=expand ("<cfile>") <CR>$<CR>
Nmap <c-_>d:cs Find D <c-r>=expand ("<cword>") <CR><CR>
When the cursor is over a word you are looking for, pressing &LT;C-_&GT;G is the definition of the object, and the other is the same. Press this key combination has a bit of skill, press the <C-_> to immediately press a key, otherwise the screen flashes back to Nomal state <c-_ The >g is to press "ctrl+shift+-" first, then press "G" very quickly. Finally, optimize it based on the code above. The characteristics of the ctags. and the summary cscope before the definition code added to get the following finally code, the following content into the ~/.VIMRC, so that the corresponding shortcut can be used to find a different. if has ("Cscope") set Cscopetag "enable support with CTRL +] and ctrl+t shortcut keys to jump between code "Check cscope for definition of a symbol before checking ctags: set to 1 if you want the reverse search order. Set Csto=1
"Add any Cscope database in current directory if Filereadable ("Cscope.out") CS Add cscope.out the Else add the database pointed to by environment variable ElseIf $CSCOPE _db! = "" CS Add $CSCOPE _db endif
"Show msg when all other Cscope DB added Set Cscopeverbose
nmap <c-/>s:cs Find S <c-r>=expand ("<cword>") <CR><CR> nmap <c-/>g:cs Find G <c-r>=expand ("<cword>") <CR><CR> nmap <c-/>c:cs Find C <c-r>=expand ("<cword>") <CR><CR> nmap <c-/>t:cs Find T <c-r>=expand ("<cword>") <CR><CR> nmap <c-/>e:cs Find e <c-r>=expand ("<cword>") <CR><CR> Nmap <c-/>f:cs find F <c-r>=expand ("<cfile>") <CR><CR> nmap <c-/>i:cs Find I ^<c-r>=expand ("<cfile>") <CR>$<CR> nmap <c-/>d:cs Find D <c-r>=expand ("<cword>") <CR><CR> endif
With frequently used commands:: CS Find s----find the C language symbol, that is, find the function name, macro, enumeration value, etc. where it appears: CS Find g----find the location of functions, macros, enumerations, and other definitions, similar to the functions provided by Ctags: CS Find D-- --Find the function called by the function: CS Find c----Find the function calling this function: CS find T:----Find the specified string: CS Find e----find egrep mode. Equivalent to the Egrep function. But the search speed is much faster: CS Find f----Find and open the file, similar to Vim's find function: CS Find I----find the text containing this file Ctrl +] will jump to the cursor where the variable or function is defined ctrl+t return



Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Linux Core Reading Tools Vim+ctags+cscope+taglist

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.