A couple of weeks ago I had a tongue-in-check conversation with Mike Schinkel on Twitter about using Vim for WordPress development. PHP Storm had just released a preview of the next version of their IDE with improved support for WordPress.

That conversation got me thinking about what it would take to build something similar for Vim. The answer, as it turns out was not a lot. All of the pieces of the puzzle were already present. They just needed putting together.

Today I’m announcing the first release of WordPress.vim. A plugin for rapid WordPress Development in Vim! It has most of the features that you come to expect in a Modern WordPress Development environment with more to come!

Auto Completion

This seemed like the most difficult problem to solve. But I soon discovered that it had already been solved by Shawn Biddle with phpcomplete.vim.

All that was needed was to teach phpcomplete to pick up the WordPress API. PHPcomplete has a builtin dictionary that it uses to offer completions. My plan was to manually add the WordPress API to it.

Ten minutes later after repeated trips to-and-from the Codex, I quickly came to my senses. The WordPress API is HUGE! Copy-Pasting this stuff manually was out.

Time for Plan B!

The WordPress inline documentation is quite extensive. Can we use that? Yes we can!

The PHPDocumenter project turned out to be the answer. It can parse all the documentation from WordPress Core and spit out a nice XML(bleh!) file with all the meta information necessary.

Some Ruby & Nokogiri later, we have a scanned Project structure made of the Core Classes and Functions. The final hurdle was to take this Project and generate out a Vim dictionary that can be used by phpcomplete. Some ifdefs and minor Viml tweaking and we have Auto-Completion!

Custom Syntax Highlighting

With the AutoCompletion done, the Syntax Higlighting turned out to be straightforward. The XML already had the meta information with the @deprecated tags.

Scanning those gave have a list of deprecated functions. Emitting a syntax file with the appropriate syn regions was easy in comparison.

WP-CLI

The integration with WP-CLI turned out to be the most work in the Plugin. So far I had been using !wp {command} but that didn’t quite feel satisfactory. It required you to be in the right directory so opening files across projects was difficult.

And I’d also grown fond of using wp post create & wp post edit . These commands are excellent to quickly create test posts. But they require opening and closing Vim to work.

In the end I decide to go with ex commands of the form :W{command} . For the common commands the :W{command} just calls the corresponding wp {command} in the WpCliCommand object. And commands that need to change the default behaviour can extend this object.

A result of this design is,

:Weval which can wp eval selections,

which can selections, :Wevalfile which can wp evalfile the current file

which can the current file :Wpost create & edit which create & update posts in the same buffer.

which create & update posts in the same buffer. :Wscaffold which directly jumps to the main scaffolded file.

Other Useful Features

UltiSnips is easily the best Snippets Engine for Vim. Snippets are included for Custom Post Types, Taxonomies, Theme Header, and so on. I’m hoping the WordPress community will add to this initial collection of snippets.

Jump to Core Definition allows you to jump to the definition of a function in Core. This comes in handy when you need to figure out how something is implemented inside WordPress.

Also included is Markdown Syntax Highlighting for the readme.txt with support for embedded PHP.

Features in the Works

Some other useful features that are in the works.

WordPress Hook Integration. The Meta information exists in the structure.xml. Just need to figure how to present this.

Find word under cursor in the Codex

Integration with the wpseek.com API.

Final Thoughts

WordPress.vim needs the help of the WordPress community to keep improving. Please consider joining this effort by providing new snippets, new features or bug reports.

If you find that a feature is missing or find a big, please contact me or and add an issue to the issues tracker on GitHub.

For further details on setting up a development environment for WordPress.vim and the implementation of the plugin see CONTRIBUTING.md.

WordPress.vim is MIT Licensed and available on Github.