PHPBuilder - Using Vim for Your PHP Development Page 2



RSS Twitter
Articles Tools

Using Vim for Your PHP Development - Page 2

by: W. Jason Gilmore
|
September 22, 2010

PHP Command Completion in Vim

Even with 13 years of experience developing websites with PHP, I still manage to forget the name or parameter ordering of various native functions regularly. Vim removes the need to refer to the manual constantly thanks to its native omni completion feature, which supports command completion for dozens of languages, PHP included. To enable this feature, create a new file named .vimrc in your home directory and add the following line:
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
The .vimrc file is useful for managing configuration settings, which Vim will read each time the program is started. The above command will enable code completion for the PHP language. Once saved, restart Vim and open the books.php script again. Enter insert mode and type da, followed by Ctrl+x, Ctrl+o, and you'll see a select box similar to that shown in Figure 2.


Click here for larger image

Figure 2. Using PHP Command Completion
Use your arrow keys to select the desired function, pressing enter to insert it into the text. Experienced PHP developers will recognize that the five functions shown in this list are just a few supported by PHP 5.3.X. This is because the command-completion file tends to lag behind the latest release, so if you suspect that the command you're looking for isn't in the select box, refer to the manual just to be sure.

Taking Advantage of Vim Plugins

Vim is an extensible IDE and developers around the world have created hundreds of useful plugins that make your life as a developer much easier. Project is one such plugin, which allows you to manage and access files associated with a particular project easily. Figure 3 illustrates how Project will provide you with immediate and convenient access to a project's files. (See the Project homepage for configuration instructions.)


Click here for larger image

Figure 3. Using the Project Plugin

Conclusion

As this tutorial demonstrated, when you become familiar with Vim's command sequences, it's possible to write and manage scripts with amazing speed.

About the Author

Jason Gilmore is the founder of WJGilmore.com and the author of several popular books, including "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and "Beginning PHP and MySQL, Third Edition".

« Previous Page
1
|
2

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
W. Jason Gilmore

Comment:



Comment:

(Maximum characters: 1200). You have characters left.