Installation and use of Vim plugin Ctags

Source: Internet
Author: User
Tags function definition

"Ctags Features":

Generate index files for source variables/objects, structs/classes, functions/interfaces, macros, etc. for quick positioning. Currently supports 41 languages.

"Installation of Ctags"
1) Online Installation:

sudo apt-get install ctags (Ubuntu)

(Redhat series use: Yum install ctags)
If this is not successful, it may be because of the source problem, change the software source update after the above command re-execute.


2) manually download the installation:
Reference steps (Take version 5.8 ctags-5.8.tar.gz for example)
After decompression
$ CD ctags-5.8
$./configure
$ make
# make Install
After installation, use the Ctags command to test for success
Or Whatis ctags, Whereis ctags, etc.

"Generate tags File"
After the installation is successful, to generate tags files for the source files, you can enjoy ctags for reading the code to bring convenience.

$ ctags-r
Generate tags files recursively for all code files in the current directory and subdirectories

Generate a tags file for some source code, using the following command
$ ctags filename.c filename1.c file.h
Or
$ ctags *.c *.h

In order to make the field completion valid, in the generation of tags need some additional parameters, the recommended C + + parameters are mainly:
Ctags-r--c++-kinds=+px--fields=+ias--extra=+q
which
Option C++-kinds is used to specify the tags record type for the C + + language,--c-kinds is used to specify the C language, and the common format is--{language}-kinds
Option Fileds to specify the extended field fields for each marker
The extra option is used to add additional entries: F indicates that an entry is added for each file, and Q adds an entry for each class

"How to use"
When the vim opens the source code, specifies the tags file, is normal use, usually manually specified, at the VIM command line input:
: Set Tags=./tags (tags file under current path)
To refer to multiple tags files in different directories, you can separate them with commas

Or, set ~/.VIMRC, add a row, you do not have to manually set the tags path:
Set Tags=~/path/tags

To add a system function or tag tag for a global variable, you need to do:
Ctags-i __throw–file-scope=yes–langmap=c:+.h–languages=c,c++–links=yes–c-kinds=+p--fields=+s-r-F ~/.vim/systags/ Usr/include/usr/local/include
and added in ~/.VIMRC (also by the manual addition described above):
Set Tags+=~/.vim/systags
In this way, you can enjoy the system library function name completion, prototype preview and other functions.

If you frequently check the code in different projects, you can add it in ~/.VIMRC:
Set tags=tags;
Set Autochdir

Set the tags file, the most commonly used shortcut keys when locating variable/function definitions are:
Ctrl +]
Jump to the definition of a variable or function, or use the command
: Ta Name
and using shortcut key combinations
Ctrl + o/t
Returns to the position before the jump.

In addition, Ctags does not generate indexes for local variables, but it is also fairly fast to use the GD key combination (Quick Find and locate the word where the cursor is located).

$ vim-t Myadd
When you open a file with Vim, the add parameter-T funcname automatically opens the file that defines the function and navigates to the first line of the definition, above which is to find the Myadd defined file open and place the cursor at the first line of the definition.

: Tags
The Find/Jump process is listed (the list of tags passed)


Also, attach the other useful shortcuts in the VIM environment:
* Navigate to the next occurrence of the word that the current light cursor refers to
# Navigates to the last occurrence of the word indicated by the current light cursor
n position to jump to the next occurrence of a word that has been marked
Shift+n to jump to the last occurrence of a word that has been marked


For more detailed ctags usage, use in vim
: Help Tags

Now go back and learn the VIM handbook.

: Help usr_29

But there is a small flaw, you modify the program, such as adding a function definition, delete the variable definition, tags file can not be automatically rebuild, you must manually run the command:

$ ctags-r

Let the tags file update, but it is gratifying that VIM does not have to restart, the program is being written do not quit, you can immediately and correctly use <C-]> and <C-T>

Installation and use of Vim plugin Ctags

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.