Using Vim for Your PHP Development - Page 2

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.

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.)