Vim Tips Wiki
(should we delete this tip?)
 
(3 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
|previous=1190
 
|previous=1190
 
|next=1194
 
|next=1194
|created=March 31, 2006
+
|created=2006
 
|complexity=basic
 
|complexity=basic
|author=Anon
+
|author=
 
|version=6.0
 
|version=6.0
 
|rating=24/9
 
|rating=24/9
Line 19: Line 19:
 
</pre>
 
</pre>
   
You can automatically load this syntax for all html files by adding the following line to your vimrc
+
You can automatically load this syntax for all html files by adding the following line to your vimrc:
 
 
<pre>
 
<pre>
 
au BufRead *.html set filetype=htmlm4
 
au BufRead *.html set filetype=htmlm4
Line 27: Line 26:
   
 
==Comments==
 
==Comments==
This tip is FALSE. htmlm4 is a filetype for documents which contain both HTML and M4 parts and syntax/htmlm4.vim just combine syntax/html.vim and syntax/m4.vim, so that there is no special treatment on embedded CSS/javascript in syntax/htmlm4.vim. Such treatment is a part of syntax/html.vim. So that this tip is false. You don't have to do the above configuration.
+
This tip is FALSE. htmlm4 is a filetype for documents which contain both HTML and M4 parts and syntax/htmlm4.vim just combine syntax/html.vim and syntax/m4.vim, so that there is no special treatment on embedded CSS/javascript in syntax/htmlm4.vim. Such treatment is a part of syntax/html.vim. So that this tip is false. You don't have to do the above configuration.
   
 
:Thanks, but please spell out what you think we on the wiki should do (assuming I don't want to take the time to figure it all out). Are you saying:
 
:Thanks, but please spell out what you think we on the wiki should do (assuming I don't want to take the time to figure it all out). Are you saying:
Line 35: Line 34:
 
:#We should delete this tip.
 
:#We should delete this tip.
 
:[[User:JohnBeckett|JohnBeckett]] 10:10, 18 June 2009 (UTC)
 
:[[User:JohnBeckett|JohnBeckett]] 10:10, 18 June 2009 (UTC)
  +
  +
Try it for your self, at least in my w3 compliant html file with embed js, syntax/html doesn't give the correct highlighting but syntax/htmlm4 does. For that reason alone I think this page should stay. A counter intuative and suprising work around, but if it works, it works.
  +
  +
  +
:After setting filetype=html4 on my file with a bunch of HTML and a bunch of Javascript that was getting highlighted poorly, I tried 'set filetype=html' which worked well. I don't really know the details on what happened, but its worth a try. YMMV.
  +
:[[User:Dschnau|Dschnau10]] November 1 2012

Latest revision as of 14:53, 1 November 2012

Tip 1193 Printable Monobook Previous Next

created 2006 · complexity basic · version 6.0


Just use the "htmlm4.vim" syntax script. (I got this from VimTip1041, but it was non-obvious to somebody looking for a quick answer.)

Put simply, while in normal mode, type the following:

:set filetype=htmlm4

You can automatically load this syntax for all html files by adding the following line to your vimrc:

au BufRead *.html set filetype=htmlm4


Comments[]

This tip is FALSE. htmlm4 is a filetype for documents which contain both HTML and M4 parts and syntax/htmlm4.vim just combine syntax/html.vim and syntax/m4.vim, so that there is no special treatment on embedded CSS/javascript in syntax/htmlm4.vim. Such treatment is a part of syntax/html.vim. So that this tip is false. You don't have to do the above configuration.

Thanks, but please spell out what you think we on the wiki should do (assuming I don't want to take the time to figure it all out). Are you saying:
  1. The title of the tip is "Syntax highlighting for HTML with embedded Javascript".
  2. You automatically get that functionality (assuming say Vim 7) if filetype is html.
  3. So there is nothing in this tip that is worth keeping.
  4. We should delete this tip.
JohnBeckett 10:10, 18 June 2009 (UTC)

Try it for your self, at least in my w3 compliant html file with embed js, syntax/html doesn't give the correct highlighting but syntax/htmlm4 does. For that reason alone I think this page should stay. A counter intuative and suprising work around, but if it works, it works.


After setting filetype=html4 on my file with a bunch of HTML and a bunch of Javascript that was getting highlighted poorly, I tried 'set filetype=html' which worked well. I don't really know the details on what happened, but its worth a try. YMMV.
Dschnau10 November 1 2012