Vim Syntax highlighting for Apache Config Files

Published on 2010-06-09 09:12:00+00:00
apache   django   vim  

I use Django with Apache and mod_wsgi. Each project that I work on has different apache config files, so I like to keep those in the same mercurial repo that contains my django project's code.

For some time now, it's been bugging me that vim doesn't do syntax highlighting for those apache configs (nor the wsgi files). I finally decided to do something about it, and I'm glad I did, because it's a fairly simple fix:

My project directory layout often look like this:


Vim does syntax highlighting for apache files based on their path. To get vim to recognize the files in the apache_configs directory, you need to edit (or create) ~/.vim/filetype.vim and add the following:

au BufNewFile,BufRead ~/django_projects/de_concierge/apache_configs/*wsgi setf python  
au BufNewFile,BufRead ~/django_projects/de_concierge/apache_configs/* setf apache   

You'd have to add variants of this for each separate project, but this works well for me.

There's several other ways you can modify this, and the solution that I used comes from this thread on the vim_mac mailing list. (There's also a lot of good info in :help new-filetype ).