Ferry Boender

Programmer, DevOpper, Open Source enthusiast.

Email: ferry.boender@gmail.com
Github: https://www.github.com/fboender
Résumé: PDF, Dutch
PGP key: PGP key
Blog: Electricmonk.nl
Keybase: fboender

Vim tip: Recognise syntax for other extensions

Monday, July 9th, 2007

If you want Vim to recognise files with other extensions as a certain syntax, this tip is for you. For instance, many people name their include files in PHP .inc (Coincidentally, not a very smart thing to do, but anyway). But Vim won't recognise files with the .inc extension as PHP. Here's how to deal with that:

Edit your .vimrc and add the following lines:

if has("autocmd")
  augroup php
    autocmd BufRead *.inc set filetype=php
  augroup END

This will make Vim recognise .inc files as PHP files and treat them accordingly (syntax highlighting and whatever else you've set Vim up to do with PHP files).

Security note: It's not a good idea to name files that will be included '.inc'. Bad configuration of your webserver may make the source of those file available unparsed through your webserver. Either name them .inc.php, or don't place them in a dir under your webroot.

The text of all posts on this blog, unless specificly mentioned otherwise, are licensed under this license.