Visual studio code comment in HTML files
Solution 1
Finally i found what the problem was. I had installed the twig plugin (for the Twig php template engine) and that was causing the comments issue.
Solution 2
I've just installing VSCode 1.1.1 and try to put a comment in an new html file To do so, your new file must be,first, save in .html format and after that, you can use CTRL-K CTRL-C to put a comment and it works.
Hope that help you
Solution 3
For me, it was the (Djaneiro) extension, it made the html files default to django template, so it caused the comments to be wrong in HTML (when pressing ctrl + / ) (commenting them with {% comment %})
Solution 4
If you don't want to disable/uninstall any plugin, you can create a snippet to put a comment. For example, I create a snippet that add HTML comments in a PHP file:
"comment HTML": {
"prefix": "chtml",
"body": ["<!-- $1 -->"],
"description": "Comment HTML line"
}
You can insert that right after the comment in File > Preferences > User Snippets > {YourExtension}
Then, when you start typing 'chtml' in that kind of files, IntelliSense will prompt that snippet.
Maybe this is a workarround, but it works excellent for me. Hope it helps!
https://code.visualstudio.com/docs/customization/userdefinedsnippets
Solution 5
List of extensions known to cause this unwanted behavior (Based on my own experience and other answers):
- Hugo Language and Syntax Support
- Djaneiro
- Nunjucks
- Tornado
- Sublime Babel
- Babel
- Twig
- Django by Baptiste Darthenay (v1.0.0)
- (Feel free to edit this answer and add yours)
You may need to restart code after disabling your extension (I did).
Related videos on Youtube
Makis K.
Graduated from University of Peloponnese in Computer Science and Information Technology. I am currently working as a Web Developer ninja in Desquared where we make magic things happen. Passionate about lots of things but my true love is development. I never get tired of learning new technologies, trying new things and constanlty expanding my knowledge.
Updated on July 31, 2022Comments
-
Makis K. almost 2 years
I am trying Visual Studio Code lately and i've noticed that when i try to add a line comment in an HTML file (using Ctrl+/ or Ctrl+K Ctrl+C) instead of this:
<!-- -->
, i get this{# #}
.In JS or CSS files the key bindings work just fine and produce the expected result.
So how can i get the proper type of comments in HTML files?
-
trivita about 4 yearsfor me, the offender is Jinja syntax support took me a while to do the trial-err
-
Jonathan about 2 yearsFor me the offender was Hugo Language and Syntax Support
-
-
Makis K. almost 8 yearsWell i installed the latest version of VSCode 1.1.1 on a new machine and the comments work as expected. But i still have the issue on my other pc (same version 1.1.1 but got it from updates). I think that's maybe a configuration that instead of <!-- --> returns {# #} for HTML files and i want to find that and change it. Or else i 'll try to uninstall and reinstall.
-
adripanico almost 8 yearsI was getting crazy about this! Thanks!
-
Daniel Tonon over 5 yearsThanks :) If you need Twig support, install this extension instead: marketplace.visualstudio.com/…
-
Daniel Tonon over 5 yearsOr maybe this one, it looks like it has more features: marketplace.visualstudio.com/…
-
tonix about 4 yearsI confirm. The problem is with the Twig Language 0.9.0 extension. Use marketplace.visualstudio.com/… and/or marketplace.visualstudio.com/… instead.
-
perhelion over 3 yearsthat was not the question dude
-
Mindaugas Bernatavičius almost 3 yearsJinja (by wholroyd) breaks the commenting ability with ctrl + / when inside embedded css.
-
MeVR about 2 yearsThis was the issue for me i disabled it , Thanks @tonix