per file configuration in vim – the modeline

I wanted a certain file to be highlighted as a PHP file despite the fact it was a .html file, and do to this you use the ‘modeline’ feature of Vim.

To do this, on line2 of the file, I put the following

 // vim:set filetype=php: 

For me, it didn’t work immediatly, the following command showed why though.

:verbose set modeline? modelines? 

By default in gentoo, the modeline is disabled in /etc/vim/vimrc, so either remove that line from there, or in your .vimrc put ‘set modeline’. The modelines option tells vim how many llines to look at at the beginning and the end of the file.

For more information, type ‘:he modeline’ in vim to bring up the relivent part of the manual

One thought on “per file configuration in vim – the modeline”

  1. Just wanted to say thank you for this! Your post not only solved my issue (getting the modeline to work in vim in gentoo) but also explained how you figured it out. I wish more articles were did this. Hence, thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.