Use vim to develop php, and use tags to redirect class function variables

Source: Internet
Author: User

From: http://www.kukaka.org/home/showonews/372

It took a long time to use vim as a PHP development tool. Previously, netbeans was used to directly press ctrl and then click the mouse to jump to the function definition. tracking code is very useful, I was not used to switch to vim. Although I knew early in the morning that the tag can also implement this function, I just couldn't try it. Now, I am quite clear about the working principle of the tag, I would like to record it and share it with my friends who are engaged in PHP development and especially fond of vim.

My working environment is Ubuntu, so the testing environment in this article is also Ubuntu.

Compile and install ctags

: Http://ctags.sourceforge.net/

Download file: ctags-5.8.tar.gz

Unzip ctags: tar-zxcf ctags-5.8.tar.gz

Go to ctags: cd ctags-5.8

Patch PHP5:

Wget http://svn.bitflux.ch/repos/public/misc/ctags-php5.patch

Patch php. c ctags-php5.patch

Compile and install:

./Configure

Make

Sudo make install

After these three steps,/usr/local/bin/ctags will be generated.

Use ctags

Run ctags-R in the corresponding source code directory to generate the corresponding tags File

Cd ~ /Www/website

Ctags
-R *

At this time ~ Generate a tags file under the/www/website directory

Now let's go to VIM and execute the following command:

: Cd ~ /Www/website "switch the current directory ~ /Www/website
: Set
Tags = tags "set the tags option to the tags file in the current directory

Now, we have set the tags option. Next we will use it to find a method named make_html:

: Tag
Make_html

If the definition of the make_html method only exists in one file, you will see that VIM has opened ~ /Www/my_function.php file, and move the cursor to the row where the make_html method is located.

If the definition of the make_html method exists in multiple files, the following message is displayed:

Find
Tag: 1/14 or more

In this case, we can list all the files protecting this method.

: Tselect
"Display list

All files will be listed. Let's select a file to open it.

# Pri kind tag file

> 1 f c f make_html function/my_function.php

2 F f make_html xxx/xxx. php

Enter a number and press enter (empty cacels ):

Enter the serial number of the file you want to view as prompted and press Enter.

: Tn
"The php file to which the last tag is displayed

: Tp "displays the PHP file from the previous tag

: Tags "display tag Stack

We can also move the mouse over the class we want to jump.
Above the function variable, press ctrl
+], Return to the original location is ctrl
+ T

Tag file format

The Tag File follows a certain format. The default format is as follows:

{Tagname} {TAB} {tagfile} {TAB} {tagaddress} {term} {field }..

The name of the {tagname} identifier, such as the function name, class name, structure name, and macro. It cannot contain tabs.

{Tagfile} contains {tagname} files. It cannot contain tabs.

{Tagaddress} can locate the {tagname} Ex command at the cursor position.

{Term} is set to ";". This is to be compatible with the Vi editor, so that Vi ignores the {field} field.

{Field} .. this field is optional and is usually used to indicate that the type of {tagname} is a function, class, Macro, or other.

Between {tagname}, {tagfile}, and {tagaddress}, use a TAB character ("\ t" in C) to separate them, that is to say, {tagname} and {tagfile} cannot contain tabs.

The Tag file can start with "! A row starting with _ TAG _. It is used to add other information to the tag file. VIM can recognize two of these tags, often using the "_ TAG_FILE_SORTED" tag, for example:

! _ TAG_FILE_SORTED1 {anything}

The above tag indicates that the tag file is sorted, and the time zone is case sensitive. For the sorted tag, VIM uses the binary method for searching, which greatly accelerates the search speed; if the value is 0, the tag files are not sorted; if the value is 2, the tag files are case-insensitive.

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.