How to set vim syntax highlighting to treat file extension as html file?
I use the ez template, so the .ezt file .ezt . But many of them are normal html code.
.ezt
You can also put this in your .vimrc:
au BufReadPost *.ezt set syntax=html
:set syntax=html
Take a look at the Vim wikia topic . Some helpful tips:
As mentioned in other answers, you can use the set vim command to set the syntax. :set syntax=<type> where <type> is something like perl , html , php , etc.
:set syntax=<type>
<type>
perl
html
php
There is another mechanism that you can use to control syntax highlighting called filetype or ft for short. Like the syntax, you give it this type :set filetype=html . Other types of files: perl , php , etc.
filetype
ft
:set filetype=html
Sometimes vim "forgets" which syntax to use, especially if you mix things like php and html together. Use the keyboard shortcut Ctrl + L ( <CL> ) to get vim to update the selection.
<CL>
Note that :set syntax=xml highlighted correctly, but doesn't seem to work when you try to auto-identify a file (i.e. gg=G ).
:set syntax=xml
gg=G
When I switched to :set filetype=xml , the highlighting worked properly and the file backed off correctly.
:set filetype=xml
In a .php file (or html file) you can use Vim modline to force certain commands or settings:
1 /* vim: syntax=javascript 2 * 3 * .submit_norefresh() ~ ~