Vim + ctags

Source: Internet
Author: User
Vim + ctags-general Linux technology-Linux programming and kernel information. For details, refer to the following section. Vi is familiar to everyone. In some cases, it is the only available text editor in Linux. In fact, the VI we usually refer to is actually VIM (ViImproved, VI enhanced version ). Some people often compare VIM with emacs. Although VIM does not have as many features as emacs, it is more convenient and easy to use than emacs. VIM is easy to use. You only need to look at the built-in vitutor of VIM, and you only need to know how to use VIM in about 20 minutes. For C/C ++ programmers in Linux, using the combination of VIM + Ctags to write programs may be the best choice.

This article assumes that you have spent 20 minutes learning vitutor.

This section describes the Ctags program. Although ctags supports other editors, it only officially supports VIM. Ctags has been installed by default in VIM, which helps programmers easily browse the source code.

To use ctags skillfully, you only need to remember the following seven commands: (very simple, huh, huh)

1. $ ctags? R * ($ is a Linux Shell prompt)
2. $ vi? T tag (replace the tag with the variable or function name you want to search)
3.: ts (the command starting with ":" In tags list is the command line mode command in VI)
4.: tp (tp note: tags preview )-? This command is not commonly used and does not need to be noted
5.: tn (tn: tags next )-? This command is not commonly used and does not need to be noted
6. Ctrl +]
7. Ctrl + T

Next we will explain the above commands one by one:
"$ Ctags? R * ":"-R "indicates recursive creation, which includes all subdirectories under the source code root directory (current directory. "*" Indicates all files. This command will generate a "tags" file in the current directory. When you run vi in the current directory, it will automatically load this tags file. The Tags file contains a list of these objects:

Macro defined by # define
Enumerated variable value
Function Definition, prototype, and Declaration
Namespace)
Type Definition (typedefs)
Variables (including definitions and declarations)
Class, struct, enum, and union)
Class, structure, and union member variables or functions

VIM uses this "tags" file to locate the marked objects above.

The remaining commands are the methods for locating these objects:
"$ Vi? T tag ": Add the"-t "parameter when running vim, for example:
[/Usr/src] $ vim-t main

This command will open the file defining "main" (variable or function or other), and move the cursor to this line. If this variable or function has multiple definitions, the ": ts" command in the VI command line mode can list a list for users to choose from. ": Tp" is the last tag file, and ": tn" is the next tag file. Of course, if the current tags file contains only one variable or function name, the ": tp,: tn" command is unavailable.

The most convenient way is to move the cursor over the variable or function name, and then press "Ctrl +]" to directly jump to the source file of the variable or function definition, position the cursor to this line. You can use "Ctrl + t" to return the original location. Even if you use "Ctrl +]" for N times to find N variables, you can press "Ctrl + t" for N times to return to the originally opened file, which will be returned in the original way.

Note: When running vim, you must run it in the directory where the "tags" file is located. Otherwise, run the ": settags =" command to set the path of the "tags" file so that vim can find the "tags" file. When coding, You can manually delete the tags file (dust will not run away ).

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.