Vim+ctags Linux Source reading artifact

Source: Internet
Author: User

Vim+ctags can easily access the Linux kernel source code. Ctags, Cscope, tlist several tools can be shared.
First, ctags!. In fact, it is only used to generate a tags file, that is, the source code objects found, and recorded, put into the tags file. The rest of the work is given to vim.
A list of these objects is included in the "tags" file:

① macros defined with # define

② The value of the enumeration type variable

Definitions, prototypes, and declarations of ③ functions

④ name Space (namespace)

⑤ type definition (typedefs)

⑥ variables (including definitions and declarations)

⑦ Class (Class), struct (struct), enum type (enum), and Union (Union) class, struct, and union member variables or functions
How to use Vim+ctags to view the source code?
First, you install Ctags.
$ sudo apt-get install Ctags
Then, go to the source directory: Use the CTAGS-R command to generate a tags file. (Parameter-r indicates that all files in this directory are included)
/usr/src/linux-2.6.30$ sudo tags-r
You can also use the make Tags command, which simply includes the files of your chosen architecture in the tags file. Tags-r is the inclusion of all architectures.
/usr/src/linux-2.6.30$ sudo make tags
(wait patiently for a while, after all, the kernel file is very large)


Next, you can use the command to find the desired function or struct body, etc.

Some common methods of finding are as follows:
1) use the command line. When running vim with the "-T" parameter, (it must be in the same directory as the build tags file) For example:
# vim-t Foo_bar
This command opens a file that defines "Foo_bar" (a variable or function or other) and positions the cursor in this line.
2) in any of the files that vim has opened, make vim in command mode, using the ": Tag" command, for example:
: Tag Foo_bar
If you are looking for a struct definition you can use the TS command, also in command line mode, enter: TS XX (structure to find)
At this time Vim will show you a lot of, with a space to page, write down the corresponding number you are looking for, always press the SPACEBAR until you are prompted to enter a number. Enter the corresponding number and the carriage return will jump to the definition of the struct you are looking for.
3) The most convenient way is to move the cursor to the variable name or function name, and then press "CTRL"; "Ctrl-o" to return to the original place. With Ctrl] Deferred call Tree forward, with Ctrl-t to jump back (of course, this is to build you have opened the file on the basis of it! )
4) Split window
The ": Tag" command replaces the current window's file with the file containing the new function. How can I see two files at a time? You can use the ": Split" command to separate the windows and then use the ": Tag" command. Vim has an abbreviated command to do this:
: Stag tagname
Use the following command to split the current window and jump to the label under the cursor:
Ctrl-w-]
If you specify a count parameter, the new window will contain as many rows as you specify.
There are basically enough of these usages, and a little more is basically the flexible use of vim. In addition, if these do not meet your requirements, you can use Find and grep to help. If you want to find FORK.C, you can use in the kernel directory input: Find-name fork.c
/usr/src/linux-2.6.30.5$ Find-name fork.c
./KERNEL/FORK.C

Vim+ctags Linux Source reading artifact

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.