Configure vim to add a navigation prompt for the php development Compiler

Source: Internet
Author: User
Tags prototype definition netbeans
The NERDtree, taglist, AutoComplPop, ZenCoding plug-in, and some configurations are used. The specific steps are as follows: Install vim settings in the previous article: here we will introduce the above settings to enable style highlighting and line number display, as well as edit functions such as parentheses matching and automatic indentation, you can enjoy an ideal editing experience in most cases. However

The NERDtree, taglist, AutoComplPop, ZenCoding plug-in, and some configurations are used. The specific steps are as follows: Install vim settings in the previous article: here we will introduce the above settings to enable style highlighting and line number display, as well as the edit functions such as parentheses matching and automatic indentation, you can get the desired editing experience in most cases. However

The NERDtree, taglist, AutoComplPop, ZenCoding plug-ins and some

Configuration. The procedure is as follows:

Install vim

Settings are described in the previous article:

The preceding settings enable formatting highlight, line number display, and edit functions such as parentheses matching and automatic indent.

The editing experience you want. However, the support for. php files is not complete yet. You need to download a dedicated php plug-in.

: Http://download.csdn.net/download/akmumu2010/4745210
Download file: php.tar.gz

Copy the php. vim file to the $ VIM \ vimfiles \ syntax directory. $ VIM: based on different systems, I use ubuntu to execute

Whereis vim:

Root @ Cyrec-desktop:/usr/share/vim/vimfiles # whereis vim
Vim:/usr/bin/vim. basic/etc/vim/usr/share/man/man1/vim.1.gz you can find vim Installation

In/usr/share/vim, the following/usr/share/vim is replaced by $ VIM.

At the beginning, the topic cannot be displayed after being changed in the settings, and the cause of the problem is found:

Generally, the default terminal of the Linux release version is 16 colors, but in fact almost all terminals support 256 colors.

1. Set Terminal to Xterm mode: Edit-> configure file preferences-> set color to custom, and select XTerm as the built-in solution.

2. set t_Co = 256 in vimrc

Then you can enjoy the theme with color. I use colorscheme desert.

Build a PHP IDE

The left side of IDE is the directory navigation, the middle is the editing area, and the right side is the method list, which is used to quickly jump to an opened file. In the editing area

Press CTRL + X to display the list of opened files.

Other functions such as auto-completion and code template are all available. After reading the beautiful ones, let's build a php ide step by step.

Use NERDTree to implement directory navigation

It is normal to edit multiple files simultaneously during PHP application development. Therefore, you must have a convenient directory navigation tool

Quickly switch between recording structures and find the file to be edited.

There are many plug-ins in vim that provide such functions, such as project and winmanager. But I personally think it is best to use

NERD Tree plug-in. The NERDTree not only displays the complete directory tree structure, but also sets any directory as the root directory. And

It also provides the directory navigation bookmarks function, which is very convenient.

: Http://download.csdn.net/download/akmumu2010/4745226
Download file: NERD_tree.zip

To decompress the package, extract the complete directory structure from the package to the $ VIM \ vimfiles directory. Find $ VIM

\ Vimfiles \ doc \ NERD_tree.txt and $ VIM \ vimfiles \ plugin \ NERD_tree.vim files. Then enter the command helptags in vim.

$ VIM \ vimfiles \ doc: add the help document of NERDTree to vim.

Add the following content in _ vimrc:

"NERDTree

Map : NERDTreeToggle

The above format must be correct, optimistic about spaces, or not, and ensure that you do not conflict with other F8, and my will conflict with youdao

After you restart vim, press F8 to view a directory tree on the left. In the directory tree window, press? Key to view detailed help information

The most common operation keys are:

Buttons Function
C (uppercase C key) Set the directory where the cursor is located as the root directory
U (lower case u key) Go to the upper-level directory
O (lowercase o key, not "zero ") Expand (or collapse) the subdirectory of the directory where the cursor is located. If the cursor is at a file, open the file in the editing window.

In addition, in the directory tree window, enter the Directory: Bookmark favorites name to add the directory where the cursor is located to favorites. Next time

Use: The BookmarkToRoot favorites name can be directly transferred to this directory, and this directory is used as the root directory. For more commands, refer to

Help documentation.

Use taglist for code navigation

To solve the Directory and file navigation problems, we also need to provide an auxiliary means for code redirection. taglist is such a plug-in. Taglist

Lists classes, functions, constants, and even variables defined in open files.

: Http://download.csdn.net/download/akmumu2010/4745259
Download file: taglist_45.zip

Decompress the package to the $ VIM \ vimfiles directory, and use the helptags $ VIM \ vimfiles \ doc command to index the help text of the taglist plug-in.

File. The taglist plug-in must depend on the ctags program to work. Currently, the common ctags version is Exuberant Ctags.

Sudo apt-get install ctags, whereis ctags, and find the ctags under the ctags Directory:/usr/bin/ctags.

You can also download and install

Address: http://download.csdn.net/download/akmumu2010/4745500

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

Go to ctags: cd ctags-5.8

Install the PHP patch (otherwise press ctrl + n to connect to the basic function include and other functions ):

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.

Continue to modify it ~ /. Vim/plugin/taglist. vim

In if! Exists ('loaded _ taglist ')

Let Tlist_Ctags_Cmd = "/usr/local/bin/ctags"

Or add ~ /. Vim/. vimrc file, as long as the *. vim file can be loaded when vim is enabled

At this time, the Ctags and Taglist have been combined, and then use vim to edit the PHP file. Execute: TlistToggle, and a class function variable of the current file will appear on the right.

Remember when we were using large development tools such as netbeans eclipse, press ctrl + left-click a function to jump to the function definition. In fact, it also uses tags to track and jump, however, they will automatically scan the source code directory to generate a tags file (have they ever crashed for netbeans endless scanning ?), Vim needs to generate the tags by ourselves. This function is very beneficial to code tracking. We will implement it below

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

Cd ~ /Www/mysite

Ctags-R *

Open vim

: Cd ~ /Www/mysite

: Set tags = tags

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

Method 1:

: Tag make_html

If the definition of the make_html method only exists in one file, you will see that VIM opened the file and positioned 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:

Locate 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 "displays the PHP file mapped to the last tag
: Tp "displays the PHP file from the previous tag

We can also move the mouse over the class function variable we want to jump to, and press ctrl +] to return to the original position: ctrl + t

Method 2:

Move the mouse over make_html and press ctrl +]. How is it the same as entering tag make_html directly?

Now, we have jumped to the definition of the make_html function. We can see the detailed definition of the function and clearly know how to use this function. How can we return to the original position, press ctrl + o to return the result.

TIPS:

Careful friends may find that, as a powerful IDE, you should also solve the following problems:

1. The tree structure of the Left directory remains unchanged.

2. Comments on code blocks and delete comments.

3. indent the code block and delete the indent.

Solution:

  1. Map: NERDTreeToggle
  2. Map: TlistToggle
  3. Map t: NERDTreeMirrorgTwgtw

map  :NERDTreeToggle map  :TlistToggle map  t :NERDTreeMirrorgTwgtw

Now let's take a look at my coding habits:

First, open the vi editor.

Press F2 to open the directory tree

Select the file to open and press F4.

How about it? The effect is similar to that of a large IDE.

2. code block comments, delete comments

Note: press ctrl + v to enter the column editing mode, move the cursor up or down, mark the beginning of the row to be annotated, and then press the uppercase I, and then insert the annotator, for example, "//", and then press Esc, all comments will be made.

Delete: press ctrl + v to enter the column editing mode, select the comment part, and press d to delete the comment symbol.

3. indent the code block and delete the indent.

Indent: select the line of code to be indented (you can click it on the keyboard and select it),> (shift + .)

Delete: select the lines of code to be indented (both the keyboard and mouse are supported, select the line), <(shift + ,)

The following is a configuration file that I have been using. If you are interested, refer to it.

. Vimrc

The following two are placed in ~ /. Vim/plugin/

MY_keymap.vim keyboard ing

MY_taglist.vim taglist plug-in configuration

Copy the ctags to the $ VIM \ vim72 directory.

Add the following content in/etc/vim/vimrc and set the taglist plug-in:

""""""""""""""""""""""""

"=> Plugin configuration

""""""""""""""""""""""""

"Taglist

Let Tlist_Auto_Highlight_Tag = 1

Let Tlist_Auto_Open = 1

Let Tlist_Auto_Update = 1

Let Tlist_Close_On_Select = 0

Let Tlist_Compact_Format = 0

Let Tlist_Display_Prototype = 0

Let Tlist_Display_Tag_Scope = 1

Let Tlist_Enable_Fold_Column = 0

Let Tlist_Exit_OnlyWindow = 0

Let Tlist_File_Fold_Auto_Close = 0

Let Tlist_GainFocus_On_ToggleOpen = 1

Let Tlist_Hightlight_Tag_On_BufEnter = 1

Let Tlist_Inc_Winwidth = 0

Use ctrl + ww to switch between two windows.

In the taglist window, you can use the following shortcut keys:

Jump to the position defined by the tag under the cursor and double-click the tag.
O display the tag under the cursor in a new window
Display the prototype definition of the tag under the cursor
U update the tag in the taglist window
S. Change the sorting method and switch between name-based and order-based.
The x taglist window is zoomed in and out to facilitate viewing long tags.
+ Open a fold, same as zo
-Fold the tag, same as zc
* Open all folds, same as zR
= Fold all tags, same as zM
[[Jump to the previous file
] Jump to the next file
Q: Close the taglist window.

In vimrc, add the following settings and press F6 to open and close the taglist.

"Function and Variable list
Map : TlistToggle

Use AutoComplPop to automatically prompt code

Click the following URL to download the autocomplpop plug-in.

Http://download.csdn.net/download/akmumu2010/4745413

The downloaded file is a zip file. After decompression, there will be three folders: autoload, doc, and plugin. Go to the Vim root directory and find the name

It is the same as the three folders. Different system directories have different locations. My fedora is/usr/share/vim/vimfiles

Copy acp. vim and any other files in the folder. Restart Vim. At this time, there may be error messages

Error detected while processing/home/carlos/. vim/plugin/acp. vim:
Line 13:
* ***** Maid! *****

This is an error message released by the plug-in. You can see acp. vim In the plugin. Is a lack of the 9-9 library. This is also required for download. The address is below

Http://download.csdn.net/download/akmumu2010/4745507

Note: This error does not occur either, but the installation is downloaded just in case.

It is also a plug-in form and copied to the Vim directory in the same way.

After installation, you can.

By default, php auto-completion is not set for this plug-in. You can set a PHP function dictionary to enable auto-completion Based on the dictionary content.

Complete.

This is a PHP dictionary :.
Edit the configuration file. vimrc and add the following code to the file.
au FileType php setlocal dict+=/etc/vim/php_funclist.txt
The following is the dictionary directory address, which can be stored in one place as needed. I put it in the/etc/vim/directory. Php_funclist download: http://download.csdn.net/download/akmumu2010/4745537

Add some auto-completion configurations (added to vimrc ):

In php, auto-completion is required after "$", "->", ":", and the following code is added to. vimrc:

if !exists('g:AutoComplPop_Behavior')    let g:AutoComplPop_Behavior = {}    let g:AutoComplPop_Behavior['php'] = []    call add(g:AutoComplPop_Behavior['php'], {            \   'command'   : "\
 
  \
  
   ",             \   'pattern'   : printf('\(->\|::\|\$\)\k\{%d,}$', 0),            \   'repeat'    : 0,            \})endif
  
 

Enable auto-completion of parentheses in Vim:

: Inoremap (() I
: Inoremap) = ClosePair (')')
: Inoremap {{} I
: Inoremap} = ClosePair ('}')
: Inoremap [[] I
: Inoremap] = ClosePair (']')
: Inoremap <> I
: Inoremap> = ClosePair ('> ')

Function ClosePair (char)
If getline ('.') [col ('.')-1] = a: char
Return "\ "
Else
Return a: char
Endif
Endf

In this way, when writing code, you will not worry about losing the parentheses on the right, especially when nesting functions.

Install the ZenCoding plugin

To plugin

Put the three autoload folders in the corresponding folder. Then input helptags/etc/vim/doc in vim to import the Help file. It will be OK.

Zencoing can easily write html, some common commands:

Enter an abbreviation such as p> p # foo $ * 3> a and press ctrl + y + to expand it (note the comma). It should look like this after it is expanded.

 

  • Abbreviation of multiple lines

Enter the following information:

test1test2test3

Then, enter the row selection mode, select the three rows, and press ctrl + y +. Then, it will prompt you for the tag name to be used. TAG: Enter 'ul> li * as shown below

 
 
  • test1
  • test2
  • test3

If blockquote is input, it will become like this

  
 
 
test1 test2 test3

Enter ctrl + y + n to enter the insert mode

Enter ctrl + y + N to enter the insert mode

If the following content exists:

 
 
  • Switch Annotation

See the following section

hello world

Move the cursor to this section and enter ctrl + y +/to change

 

Input again to restore

  • Generate url Connection

Move the cursor to a url, for example:

http://www.google.com/

Enter ctrl + y + a to automatically obtain the url page title and generate a connection

 

Quick Reference Manual officially provided by Zen Coding (PDF): http://zen-coding.googlecode.com/files/ZenCodingCheatSheet.pdf

The configuration is OK. Finally, the handsome vim figure is shown:

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.