Adding the PHP Documentation to Vim

28, Mar 2013


The PHP documentation at is an awesome resource to have. Though I may have some complaints about the language as a whole, I think the documentation itself is very good. They've done an excellent job at thoroughly documenting the language, providing examples of the functions in use, and linking between similar functions. I find myself frequently visiting the docs site throughout the development process to look up return values, parameter orderings, and code examples. This can be slow and frustrating though, as it requires a jump outside your editor and thought process to another program in order to access an external website. Thankfully there's an alternative!

Offline Documentation

In my ongoing quest to improve my work flow I just discovered an additional power of Vim. The PHP team has released the PHP manual in *nix style man pages which can easily be integrated into Vim for seamless lookups of functions. By replacing the standard program that the keyword lookup 'K' does with the PHP documentation it's possible to quickly get the full documentation on any native PHP function. No longer do I need to flip between my shell and a web browser!

Install and Setup

Firstly we need to install the pman program from the PEAR doc channel:

sudo pear channel-update
sudo pear install

Once that's complete, it's time to modify the ~/.vimrc file. Since we only want to replace the K command within a PHP file, we're going to write an autocmd on the FileType to set the keyword look up program. Make the following changes to your ~/.vimrc file:

filetype on "Make sure this - or some variation thereof is present in your file
autocmd FileType php set keywordprg=pman

Save it, and you're good to go.

To test it out, open a .php file in Vim and move the cursor over a PHP native function. While in normal mode press K to pull up the documentation. By default pman will drop you into less, so you can use some of the Vim movement commands to scroll through the page. Hit q to quit out of less, and then hit any key to return back into your Vim instance. The only thing that is missing from this option is the user provided comments present on the Online Documentation, and the ability to link between different functions, but on the whole, a very awesome addition to Vim!


This space intentionally left blank.

Have Something to Say?

Questions? Comments? Concerns? Let me know what you’re thinking.

  • You can use Markdown formatting here.