How to get vim to syntactically highlight a file as html?

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.

+66
html vim syntax-highlighting
Oct 04 2018-10-10T00:
source share
5 answers

You can also put this in your .vimrc:

 au BufReadPost *.ezt set syntax=html 
+66
04 Oct 2018-10-10T00:
source share
 :set syntax=html 
+104
04 Oct 2018-10-10T00:
source share

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.

  • 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.

  • 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.

+15
Dec 12 '11 at 16:40
source share

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 ).

When I switched to :set filetype=xml , the highlighting worked properly and the file backed off correctly.

+6
Sep 20 '12 at 23:13
source share

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() ~ ~ 
+6
Nov 19 '13 at 18:19
source share



All Articles