Use Vim for PHP Development Environment

Source: Internet
Author: User
Tags php development environment
ArticleDirectory
    • Modified _ vimrc automatically takes effect
    • Enable culture in VIM
    • Set Font
    • Basic settings for editing PHP code
    • Set your favorite color scheme
    • More useful editing settings
    • Use nerdtree to implement directory navigation
    • Use taglist for code navigation

Author: Liao Yuli

Although Vim is essentially an editor. But with some appropriate plug-ins, VIM can also become a full-featured IDE. I have been using Vim for a long time. After repeated experiments, I have configured an efficient php development environment, which is a perfect product for traveling at home, killing people and killing goods.

Install Vim

Since most readers useWindowsEnvironment, so this article uses Windows as the runtime environment. However, thanks to Vim's outstanding cross-platform features, you only need to modify the configuration file inLinuxIn vim.

Currently, the latest version of VIM is 7.2. If there is no special reason, we recommend that you install the latest version.

: Http://www.vim.org/download.php#pc
Download file: ftp://ftp.vim.org/pub/vim/pc/gvim72.exe

During InstallationDo not install it in a directory with spaces or Chinese CharactersAnd keep the default value for others. The installation directory of the author isC: "apps" office "VimWhich is subject to this document. I use$ VimTo the vim installation directory. For example, if your vim is installed in D: "Vim", $ Vim represents D: "Vim ".

Start to configure Vim

We have several steps to configure vim.

Modified _ vimrc automatically takes effect

Open$ VimDirectory._ VimrcFile, use Vim to open the file, delete all content, and insert the last two lines:

"Autoload _ vimrc

Autocmd! Bufwritepost _ vimrc source %

The above command allows us to automatically load the _ vimrc file when editing and saving the _ vimrc file through vim, so that our Vim customization can take effect immediately (no need to restart Vim ).

Enable culture in VIM

Add the following text to the top of _ vimrc:

"Disable VI's compatible mode ..

Set nocompatible

"Set encoding = UTF-8

Set fileencodings = ucs-bom, UTF-8, GBK, default, Latin1

"Use Chinese help

Set helplang = Cn

AboveCodeThe function is to disable the VI compatibility mode (there are too few original VI functions and there is no need to consider compatibility), check the file encoding in the UTF-8 and GBK order, and set the help to Chinese. But setSet helplang = CnChinese help cannot be seen immediately. We have to download the Chinese help file.

: Http://vimcdoc.sourceforge.net/
Download file: vimcdoc-1.6.0.tar.gz

After you get a Chinese help file compressed packageDocCopy all the files in the subdirectory$ Vim "vimfiles" DocDirectory. Enter: HelpCommand to see the help in Chinese.

The Chinese help version is 7.1, but it does not affect our use.

Set Font

Select "edit"> "select font" in the vim menu to specify the font you like For Vim. I use the consolas font and set the size to 9pt. This setting shows that the code is very beautiful, but the Chinese language is a little distorted.

After setting, enter the command: Set guifontYou can view the current font settings and write the settings to the _ vimrc file.

"Set GUI options

If has ("gui_running ")

Set guifont = consolas: H9

Endif

In the above Code, if... Endif is a condition judgment structure. Indicates that the font is set only when we use Vim in the graphic interface version.

Basic settings for editing PHP code

Now it looks ugly to open the. php file with vim, not to mention code highlighting, and even the row number is not displayed. Therefore, add the following content to _ vimrc:

"Enable syntax highlight

Syntax enable

"Show line number

Set nu

"Show matching bracets

Set showmatch

"Basic editing options

Set expandtab

Set shiftwidth = 2

AU filetype HTML, Python, Vim, JavaScript SETl shiftwidth = 2

AU filetype HTML, Python, Vim, JavaScript SETl tabstop = 2

AU filetype Java, PHP SETl shiftwidth = 4

AU filetype Java, PHP SETl tabstop = 4

Set smarttab

Set LBR

Set Tw = 0

"Auto indent

Set AI

"Smart indet

Set Si

"C-style indeting

Set cindent

"Wrap lines

Set wrap

The preceding settings enable the formatting highlight, line number display, and edit functions such as parentheses matching and automatic indent. This gives you an ideal editing experience in most cases. However, the support for. php files is not complete yet. You need to download a dedicated PHP plug-in.

: Http://www.vim.org/scripts/script.php? Script_id = 1, 1571
Download file: php.tar.gz

Copy the php. Vim file to the $ Vim "vimfiles" syntax directory.

Set your favorite color scheme

The default color scheme is expected to be liked by a few people. You can view and download the scheme on the following URL (several hundred ).

Http://www.cs.cmu.edu /~ Maverick/vimcolorschemetest/index-c.html

This website lists more than 300 color schemes and their actual display effects. Click the solution name to download to a. Vim file. Put the file in the $ Vim "vimfiles" Colors directory and add the following in _ vimrc:

"Set color Schema

Colorscheme oceandeep

These two lines of code need to be added to IF has ("gui_running ")... In the endif code block, for example:

If has ("gui_running ")

Set guifont = consolas: H9

"Set color Schema

Colorscheme oceandeep

Endif

After setting, the display effect will be much more beautiful :-)

More useful editing settings

Although it is not specific for editing the. php file, these options can make Vim easier to use. Therefore, we recommend that you add:

"Sets how many lines of history Vim Har to remember

Set history = 400

"Set to auto read when a file is changed from the outside

Set autoread

"Have the mouse enabled all the time:

Set mouse =

"Do not redraw, when running macros... lazyredraw

Set LZ

"Set 7 lines to the curors-when moving vertical ..

Set so = 7

"The commandbar is 2 high

Set bytes Height = 2

"Change buffer-without saving

Set hid

"Ignore case when searching

"Set ignorecase

Set incsearch

"Set magic on

Set magic

"No sound on errors.

Set noerrorbells

Set novisualbell

Set t_vb =

"How many tenths of a second to blink

Set MAT = 4

"Highlight search things

Set hlsearch

"Turn backup off

Set nobackup

Set nowb

Set noswapfile

"Smart backspace

Set backspace = start, indent, EOL

"Switch buffers with Tab

Map <c-tab>: BN <CR>

Map <s-tab>: BP <CR>

After some transformation, our Vim can easily edit the. php file. However, there are still many php development environments to be created.WorkWhat to do.

Build a PHP ide

The left side of IDE is the directory navigation, the middle is the editing area, and the right side isMethodList, 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 to quickly switch between directory structures and find the files 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 the nerd tree plug-in. The nerdtree not only displays the complete directory tree structure, but also sets any directory as the root directory. It also provides the directory navigation bookmarks function, which is very convenient.

: Http://www.vim.org/scripts/script.php? Script_id = 1, 1658
Download file: nerd_tree.zip

To decompress the package, extract the complete directory structure from the package to the $ Vim "vimfiles directory. After that, find the $ Vim "vimfiles" Doc "nerd_tree.txt file and the $ Vim" vimfiles "plugin" nerd_tree.vim file. Then input the command in vim.: Helptags $ Vim "vimfiles" DocTo add the help document of nerdtree to vim.

Add the following content in _ vimrc:

"Nerdtree

Map <F10>: nerdtreetoggle <CR>

After Vim is restarted, press the F10 key 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)CKey)

Set the directory where the cursor is located as the root directory

U(Lower caseUKey)

Go to the upper-level directory

O(Lower caseOKey, 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: BookmarkAdd to favoritesYou can also add the directory where the cursor is located to the favorites folder. Next use: BookmarktorootAdd to favoritesYou can directly go to this directory and use this directory as the root directory. For more commands, see the help document of nerdtree.

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 can list classes, functions, constants, and even variables defined in open files.

: Http://www.vim.org/scripts/script.php? Script_id = 1, 273
Download file: taglist_45.zip

Decompress the package to the $ Vim "vimfiles directory, and use: Helptags $ Vim "vimfiles" DocCommand to index the help document of the taglist plug-in. The taglist plugin depends on ctags.ProgramTo work. Currently, the common ctags version is exuberant ctags.

: Http://ctags.sourceforge.net/
Download file: ec57w32.zip

Copy the ctags.exe In the compressed package to the $ Vim "vim72 directory. Ctags.exeshould be in the same directory as gvim.exe.

Add the following content in _ vimrc and set the taglist Plugin:

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

"=> 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

Let tlist_max_submenu_items = 1

Let tlist_max_tag_length = 30

Let tlist_process_file_always = 0

Let tlist_show_menu = 0

Let tlist_show_one_file = 0

Let tlist_sort_type = "order"

Let tlist_use_horiz_window = 0

Let tlist_use_right_window = 1

Let tlist_winwidth = 40

Let tlist_php_settings = 'php; C: Class; I: interfaces; D: constant; F: function'

The settings here are my personal habits. You can try them before getting familiar with the specific settings of taglist.

 

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.