Vim + ctags + taglist configuration and use

Source: Internet
Author: User
Tags function definition egrep

  vim +ctags + taglist ,ctags+cscope installation configuration and use

content: The installation and configuration method of Ctags and TagList under Vim, the method of installing ctags and cscope with one click, vim syntax highlighting, auto indent, Python auto indent settings, and the following will be described by the installation and configuration usage, for reference only:
1, vim + ctags + taglist configuration and use

TagList depends on the ctags, so the first to install Ctags, otherwise taglist installed also can't use!

1, first install Ctags

First is the installation of ctags, we recommend the use of exuberant ctags, we can download its source package from its official website, unzip, compile, install.
1) Ubuntu Installation
sudo apt-get install Exuberant-ctags

(or download manual install download ctags-5.8.tag.gz (address)

Tar xzvf ctags-5.8.tag.gz

CD ctags-5.8

./configure

sudo make

sudo make install

)

At this point, the installation of Ctags is complete and can be detected by using the Ctags command.

Detection:

Execute $ctags-R * under your own project folder (no effect if not performed)
Note: "-r" means recursive creation and includes all subdirectories under the source code root directory (current directory). "*" means all files. This command will generate a "tags" file in the current directory, and when the user runs VI in the current directory, this tags file will be loaded automatically.
Then we can start.
Common commands:
skilled use of ctags only need to remember the following seven commands: (very simple, hehe)
1. $ ctags–r * ($ for Linux system shell prompt)
2. $ vi–t Tag (please replace tag with the variable or function name you want to find)
3. : TS (TS Mnemonic: Tags list, ":" Starts with command-line mode command in VI)
4. : TP (TP mnemonic: Tags preview)---This command is not commonly used, you can not remember
5. : TN (TN mnemonic: Tags next)---This command is not commonly used, you can not remember
6. Ctrl +]
7. Ctrl + T

-------------------------------------------------------------------------------------------------

2, Installation TagList

Below we will carry on the TagList installation, same as the ctags installation here we also go to its official website to download unzip its source package.

The steps are as follows:


Unzip the file
# unzip-d TagList taglist_45.zip//Unzip to TagList

We first create a. vim file (mkdir. Vim) in the home directory to facilitate the storage of Vim's plugins. Then we unzip the TagList source package that we downloaded, and copy the doc and plugins directories to the. Vim folder. Enter into vim in command mode input Helptaglist~/.vim/doc that completes the installation of TagList. Enter Tlist in vim and the installation will prove successful if the following screen appears.


You can also configure this
$CD taglist/
$CP doc/taglist.txt/usr/share/vim/vim72/doc/
$CP plugin/taglist.vim/usr/share/vim/vim72/plugin/
Basically configuration complete
Start vim with ": Helptags." To configure the Help file
Restart Vim and use ": Tlisttoggle" to open and close the TagList window.
You can use ": Help TagList" To get more support letters
To open TAGLIST,_VIMRC by default, add

Let Tlist_auto_open=1

Set tags=tags;

Set Autochdir;

Note that the semicolon in the first command is essential. This command let vim first in the current directory to look for tags files, if not find the tags file, or do not find the corresponding target, go to the parent directory to find, always upward recursion. Because the path that is recorded in the tags file is always relative to the path where the tags file is located, use the second setting to change the current directory of Vim.

completed the installation of TagList and Ctags, but at this time ctags and TagList have not been linked up. To do this, we need to modify the ~/.vim/plugin/taglist.vim file, locate the If!exitsts (loaded_taglist) line and add let tlist_ctags_cmd= "/usr/local/bin/ctags" in front of it PS: It is important to note here that we need to look at our Ctags executable path in the setup line, we can go to the above directory, find the specific executable file Ctags, and assign its path to Tlist_ctags_cmd (for example, my path is/usr /local/bin/ctags/ctags) Vim+taglist+ctags reading code in order to use Vim+taglist+ctags to read the code, we first have to generate symbolic information for functions and variables. This step is done using Ctags. For example, let's use the source package of the ctags we just downloaded as an example. Generate Tag Execution Ctags-r * (-R recursive effect)//Check whether the generated Tagsls-l tags generated tag after I can be examined, the specific steps are as follows VIM input: Tlisttoggle to open the side window (or directly: Tlist, Tlistopen can also use Ctr and two times W to switch between the side window and the main window
After moving to the function of the soil body, press ENTER to see the specific function. (Can take advantage of the characteristics of the ctags at the mouse location such as "apue.h", nomal input GF, turn to the head file "apue.h") sometimes we want to look at the function in other code files defined, this is we just position the cursor to look at the function, and then press ctr+] Key can be viewed, press Ctr+o can jump back to the source file.

Specific VIM high-order applications see http://easwy.com/blog/archives/advanced-vim-skills-catalog/

The first step to achieve the effect is not very troublesome, here is a simple method
2, one-button installation of Ctags and Cscope method using the Vim plugin to build a similar sourceinsight VI, while adding some vim and scripts, recently saw a lot of people want to have sourceinsight function of vim, because the entire configuration is still a bit troublesome, so the configuration of vim sent up, just a command, Can install the Ctagslist,cscope,fielexporeer and other plug-ins, to achieve the sourceinsight effect.

installation process:

Download the attachment, then unzip
Then cut to the unpacked folder,
Execute sudo./install
Then execute sudo apt-get install vim

or install this:
#Clone repository:
git clone https://github.com/ustcdane/vim_install.git
#install
CD Vim_install
sudo./install

Errors may occur:
"Taglist:exuberant ctags (http://ctags.sf.net) not found in PATH.
Plugin is not loaded. "

No associated ctags and TagList

added in ~/.VIMRC: Let tlist_ctags_cmd= '/usr/bin/ctags '

In fact, I have added in the install, if the error still occurs, find your executable program Ctags where you manually add let tlist_ctags_cmd= ' your Ctags path '

User guide:

When we need to read the code, we must first generate the tags file and the cscope.out file, which can be automatically generated by the script in the installed program
For example, if you want to read the code under the source folder, use CS source
When a file is updated under source, you can use CS source-u to update

Common commands:
after entering vim
WM opens the IDE interface, and once again the WM is off
ctrl+w switch in each window
ctrl+h switch to the left window
ctrl+j Switch to the following window
ctrl+l switch to the right window
ctrl+k switch to the window above
Ctrl +] function tracking


shortcut key CS F s/g/....

s: Find the C language symbol, that is, find the function name, macro, enumeration value and other occurrences of the place
g: Find the location defined by functions, macros, enumerations, and similar functions provided by Ctags
d: Find functions called by this function
C: Find functions that call this function
T: finds the specified string
e: Find Egrep mode, equivalent to Egrep function, but find much faster
f: Find and open files, like Vim's find function
I: Find the text that contains this document
of course, typing help in the bottom row mode will pop up vim.

Use Cscope to find the definition of the Do_fork function:
Execute under the VIM command line:

: CS f g do_fork

You can see the global definition of the do_fork.

Cscope Common shortcut keys:

Press ctrl+\ First and then press the following key:

Ctrl +]: Jumps to the function definition where the function is called
ctrl+t: Go back to the last place you found


This method is learned from the internet and has been partially modified.


3, set vim syntax highlighting and auto indent

1, the location of the configuration file under directory/etc/vim, there is a file named VIMRC, this is the public vim profile in the system and is valid for all users. And in each user's home directory, you can create a private profile, named: ". VIMRC", (if you use the second step of the One-click installation of Ctags and Cscope recommended in your own home directory. VIMRC make the appropriate changes) 。 For example, under the/root directory, a. vimrc file is usually already present.
2. Set syntax highlighting
1) Open VIMRC and add the following statement to make syntax highlighting:
Syntax on
2) If the syntax is not highlighted at this point, then add the following statement in the profile file in the/etc directory:
Export Term=xterm-color

3. Set the Windows-style C + + Auto Indent (add the following set statement to VIMRC)
1) Set (soft) tab width to 4:
Set tabstop=4
Set softtabstop=4
2) Set the number of spaces in the indent to 4
Set shiftwidth=4
3) Set auto indent: The indent value of each line is equal to the previous line; Use Noautoindent to cancel the setting:
Set Autoindent
4) Set the automatic indentation using the C + + language:
Set Cindent
5) To set the specific indentation for the C + + language (in my Windows style example):
Set Cinoptions={0,1s,t0,n-2,p2s, (03s,=.5s,>1s,=1s,:1s
6) If you want to display the line number of the text on the left, you can use the following statement:
Set Nu
7) Finally, if you do not have the following statement, add it:
If &term== "Xterm"
Set T_co=8
Set T_SB=^[[4%DM
Set T_SF=^[[3%DM
endif



Summary, what you need to add:
A, syntax highlighting adds the following statement to the profile file in the/etc directory:
Export Term=xterm-color

B, other additions in/ETC/VIM/VIMRC:

[Plain]View Plaincopy
    1. Syntax on
    2. Set Nu
    3. Set tabstop=4
    4. Set softtabstop=4
    5. Set shiftwidth=4
    6. Set Cindent
    7. Set Cinoptions={0,1s,t0,n-2,p2s, (03s,=.5s,>1s,=1s,:1s
    8. If &term== "Xterm"
    9. Set T_co=8
    10. Set T_SB=^[[4%DM
    11. Set T_SF=^[[3%DM
    12. endif
    13. Hi Comment ctermfg=6



Other:vim Python's automatic indentation setting method.
The most common indentation settings are:
: filetype indent on it will open indentation for file specific type

Vim + ctags + taglist configuration and use

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.