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 preferences → browse packages → HTML
.
Open it up and look for a line that looks like the following. It should be around line 286.
<string>(?:^\s+)?(<)((?i:script))\b(?![^>]*/>)</string>
Replace it with this:
<string>(?:^\s+)?(<)((?i:script))\b(?![^>]*/>)(?!.*</script>)</string>
Save. You should now be able to properly toggle comment out script tags in Sublime Text!
Find an issue with this post? Think you could clarify, update or add something?
All my posts are available to edit on Github. Any fix, little or small, is appreciated!