Visual studio code comment in HTML files

2019-04-07 14:40发布

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?

9条回答
甜甜的少女心
2楼-- · 2019-04-07 14:52

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

查看更多
相关推荐>>
3楼-- · 2019-04-07 14:55

Click (Ctrl + K C) to comment the html. Click (Ctrl + K U) to uncomment html.

查看更多
▲ chillily
4楼-- · 2019-04-07 14:57

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

查看更多
Juvenile、少年°
5楼-- · 2019-04-07 14:57

For me, the offending extension was Nunjucks (the templating language plugin assumes every .html file is a nunjucks html template)

查看更多
劳资没心,怎么记你
6楼-- · 2019-04-07 14:58

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 %})

查看更多
一纸荒年 Trace。
7楼-- · 2019-04-07 14:59

If you are running Visual Studio Code in Mac. Then first press Cmd + k, Cmd + c immediately after that.

enter image description here

CHEERS

查看更多
登录 后发表回答