Use vim in the window for php development environment (although I have been using vim in ubuntu ).

Source: Internet
Author: User
Using vim in the window as the php development environment (although I have been using vim in ubuntu)... although vim is essentially just 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, configured an efficient PHP development window to use vim for the php development environment (although I have been using vim in ubuntu )...

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 use Windows, this article uses Windows as the runtime environment. However, thanks to vim's outstanding cross-platform features, the configuration file can be used in vim of Linux only with simple modifications.


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


Do not install it in a directory with spaces or Chinese characters during installation. keep the default values for other files. The installation directory is c: appsofficevim. For convenience, I use $ VIM to represent 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 the $ VIM directory and you will see a _ vimrc file. use vim to open the file. after deleting all the content, insert the following two lines at the end:


"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


The purpose of the above code is to disable the vi compatibility mode (there are too few original vi functions and there is no need to consider compatibility) and check the file encoding in the UTF-8 or gbk order, set help to Chinese. However, setting set helplang = cn does not immediately display Chinese help. we have to download the Chinese help file.


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


After obtaining the Chinese help file compressed package, copy all the files in the doc subdirectory in the compressed package to the $ VIMvimfilesdoc directory. Enter the help command to view 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 guifont to 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 $ VIMvimfilessyntax 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 $ VIMvimfilescolors 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: bn


Map: bp


After some transformation, our vim can easily edit the. php file. However, there is still much work to be done to build a php development environment.


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 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 $ VIMvimfiles directory. After completion, you should find the vimvimfilesdocnerd_tree.txt file and $ VIMvimfilespluginNERD_tree.vim file. Then enter the command helptags $ VIMvimfilesdoc in vim to add the help document of NERDTree to vim.


Add the following content in _ vimrc:


"NERDTree


Map: NERDTreeToggle


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 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 use: the BookmarkToRoot favorites name can be directly transferred to this directory, and this directory is used 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


The compressed package must be completely decompressed to the $ VIMvimfiles directory and indexed to the help document of the taglist plug-in using the: helptags $ VIMvimfilesdoc command. The taglist plug-in must depend on the ctags program to 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 $ VIMvim72 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.


After the settings are complete, Edit. php

Author http://ihacklog.com/php/%E7%94%A8vim%E5%81%9Aphp%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83.html

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.