404

Using the Vim Editor for Syntax Highlighting in PHP

The Vim text editor supports many different file formats and color schemes, so I wanted to see if I could harness its syntax highlighting power in PHP. The following script is the result of that effort.

To use it, the user that runs the PHP script (e.g. www-data on a default Debian installation) will need to have access to the 'vim' command (and optionally, if you want better color support, 'gvim' and 'Xvfb'). Any extra color schemes will have to be added either to the master Vim config folder, or to the runner's ~/.vim/ folder.

Once set up, using it is simple:

<?php
    require_once('VimHighlight.php');
    $hl = new VimHighlight();
    $hl->caching = true;
    $hl->color_scheme = "jellybeans";
    $hl->show_lines = true;
    $hl->use_css = false;
    $hl->setVimCommand("vim");
    echo $hl->processFile("file_to_process.php", true);
?>

Download

You can find the PHP Vim Syntax Highlighting script on GitHub.

Note: This script has recently been updated to work with Vim 7.4. Also note that Vim 7.4 uses a different class name for the line numbers. It now uses ".LineNr" instead of ".lnr". Update your CSS file accordingly.