I just launched a new course on ES6! Use the code WESBOS for $10 off.

Strengthen your core JavaScript skills and master all that ES6 has to offer. Start Now →

Fixing toggle comment on script tags in Sublime Text

Toggling comments in Sublime Text is broken and it’s time you fix it. If you work with HTML/JavaScript you have probably run into this while using the ⌘ + / comment toggle.


Sublime Text thinks it is JavaScript, so it uses a JavaScript comment! The problem is that the script tag is acutally HTML, so we need to use an HTML comment to comment it out. We want something like this:

<!-- <script src="jquery.js"></script> -->

The underlying problem is inside the HTML syntax file and it is actually an easy fix.

We need to edit the HTML.tmLanguage file that is located in preferencesbrowse packagesHTML.

Open it up and look for a line that looks like the following. It should be around line 286.


Replace it with this:


Save. You should now be able to properly toggle comment out script tags in Sublime Text!

This entry was posted in Sublime Text. Bookmark the permalink.

10 Responses to Fixing toggle comment on script tags in Sublime Text

  1. Roegr says:

    Hey Wes, just bought (and devoured) the book. Loved it and love Sublime. Any way, just came across this post and wanted to let you know that when I looked at my HTML.tm file the line was at 308 and says the following:


    I didn’t see any other comments to this post so wasn’t sure if anyone else had mentioned this variation. I am on OSX and ST3. Thanks

  2. Steve Fasano says:

    This is exactly what I was looking for! Thanks for posting this fix!

  3. Omid Ahourai says:

    Any idea how to do this in the latest version of ST3? The HTML.tmLanguage is now HTML.tmLanguage.cache, and opens to a binary file (unreadable)

  4. Chris Weiser says:

    You are he who has come to deliver us from evil and coding pain. Thank you so much for this!

  5. Right here is the right site for anyone who wishes to ffind out about this topic.
    You know soo much its almost tough to argue with you (not
    that I really will need to…HaHa). You certainly put a new spin on a topic that’s been written about for decades.
    Wonderful stuff, just excellent!

  6. Rarian says:

    This! is what I’m looking and searching for with tens of keywords!!! Thank you for escaping me from the chaos.

  7. I do not even know how I finished up right here, but I assumed
    this submit was great. I don’t know who you’re but definitely you
    are going to a well-known blogger if you are not already.

  8. Peter says:

    Thank you so much for this article! I’ve been commenting script tags by actually typing out forever, but now never again!

  9. CR says:

    This is fantastic, thank you very much √

Leave a Reply

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