Get VIM syntax highlight colors when editing Drupal .module files

user warning: Table './drinking_drpl2/watchdog' is marked as crashed and last (automatic?) repair failed query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'flickr', 'Could not connect to Flickr, Error: Forbidden', 'a:0:{}', 4, '', 'http://rothwerx.com/content/get-vim-syntax-highlight-colors-when-editing-drupal-module-files', '', '54.145.95.149', 1503100195) in /home1/drinking/public_html/rothwerx/modules/dblog/dblog.module on line 146.

Jeremiah - Posted on 12 January 2010

I'm doing more with Drupal lately, and working through the book "Pro Drupal Development". I do my editing exclusively in vim, so it's kind of annoying that vim will detect when I'm working in files with the .php extension, but not the others like .module, .inc, and .install that have PHP code in it. This is easily fixed though, at least on my Ubuntu 8.04 machine (YMMV).

  1. Create a ~/.vim directory if you don't already have one.
  2. Copy /usr/share/vim/vim71/filetype.vim to your ~/.vim directory
  3. Find the line like this: "au BufNewFile,BufRead *.php,*.php\d setf php" and add *.module,*.inc,*.install to the list of *.php extensions. Your resulting line should look something like this: au BufNewFile,BufRead *.php,*.php\d,*.module,*.inc,*.install setf php

Next time you open one of these files, you should have regular syntax highlighting.

UPDATE: Drupal has a whole page dedicated to configuring VIM for working on Drupal files. Handy! http://drupal.org/node/29325