Use of VIM + ctags

Source: Internet
Author: User

Question:
With sourceinsight in Windows, you can easily locate functions, variables, and macro definitions, so that developers can manage project code and improve development efficiency. How can you perform similar operations in Linux.
Vim can use the tags File Created by ctags to browse program source files to achieve similar functions of sourceinsight.

Usage:
1. Generate the tags File
In the root directory of the directory tree, run the command ctags-R or ctags -- recurse.
For example: ctags-r src/*, the tags file is generated in the current directory.
2. Edit the vim configuration file. vimrc
Add two rows:
Set tags = tags;
Set autochdir
Note that the semicolon in the First Command is essential. This command allows Vim to search for the tags file in the current directory first. If the tags file is not found or the corresponding target is not found, it will be searched in the parent directory, and it will go up recursively. Because the recorded path in the tags file is always relative to the path of the tags file, you need to use the second setting item to change the current directory of vim.

Of course, if you want to directly use the absolute path, this is also possible:
Set tags =/home/XXX/myproject/tags

3. When using the vim file, use ctrl-] to execute the jump. You can use Ctrl + T to jump back, which is very convenient.

Other tools:
These are not tested.
Link: Linux programming tool VIM + ctags + taglist + cppcomplete + CSTE + global

VIM + ctags + taglist use 1. ctora 7 has installed ctags. You can run the ctags-V command to view them. Go to an original file, VI test. c. Enter the command mode and enter the command ": tlist". If two columns are displayed in the left and right columns, the taglist is also installed with 2. for the installation of taglist, It is a plug-in of VIM, which can be downloaded from SourceForge. It is a zip file and is unzip. Two folders, Doc and plugin, are displayed, copy the two files to the doc and plugin under/usr/share/Vim/vim70 respectively. Next, associate ctags and taglist to modify the taglist in plugin. VIM: In command line mode, enter ":/loaded_taglist" and add the following line before the line: Let tlist_ctags_cmd = "/usr/bin/ctags ". 3. How to Use it: run the/usr/include command: ctags-R in/usr/include (usually check the function definition) and find a tags file in it. Currently, you can only use tags in/usr/include. If you want to use tags in other paths, you need to modify the vim configuration file/etc/vimrc and add: set tags =/usr/include/tags, ok4.ctrl +] view definition; Ctrl + O return 5.vim settings edit/etc/vimrc, add: 1) settings (soft) the tab width is 4:

Set tabstop = 4 set softtabstop = 4 2) set the number of spaces for indent to 4 set shiftwidth = 4 3) Set automatic indent: that is, the indent value of each line is equal to that of the previous line; use noautoindent to cancel the settings: Set autoindent 4) set the automatic indent mode in C/C ++ language: Set cindent 5) to display the line number of the text on the left, use the following statement: set number 6) Brackets match set showmatch
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.