Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Syntax highlighting for HTML with embedded Javascript
Back to page
Edit
Edit source
View history
Talk (0)
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=1193 |previous=1190 |next=1194 |created=2006 |complexity=basic |author= |version=6.0 |rating=24/9 |category1=HTML |category2=Syntax }} 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: <pre> :set filetype=htmlm4 </pre> You can automatically load this syntax for all html files by adding the following line to your vimrc: <pre> au BufRead *.html set filetype=htmlm4 </pre> ==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: :#The title of the tip is "Syntax highlighting for HTML with embedded Javascript". :#You automatically get that functionality (assuming say Vim 7) if filetype is html. :#So there is nothing in this tip that is worth keeping. :#We should delete this tip. :[[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
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab