HTML 文件中的 Visual Studio 代码注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37312056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:18:38  来源:igfitidea点击:

Visual studio code comment in HTML files

htmlcommentsvisual-studio-codekey-bindingscode-editor

提问by Makis K.

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 {# #}.

我最近正在尝试 Visual Studio Code,我注意到当我尝试在 HTML 文件中添加行注释时(使用 Ctrl+/ 或 Ctrl+K Ctrl+C)而不是这个:<!-- -->,我得到了这个{# #}

In JS or CSS files the key bindings work just fine and produce the expected result.

在 JS 或 CSS 文件中,键绑定工作得很好并产生预期的结果。

So how can i get the proper type of comments in HTML files?

那么如何在 HTML 文件中获得正确类型的注释呢?

回答by Makis K.

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.

最后我找到了问题所在。我已经安装了 Twig 插件(用于 Twig php 模板引擎),这导致了评论问题。

回答by user3679671

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.

我刚刚安装了 VSCode 1.1.1 并尝试在新的 html 文件中添加注释为此,您的新文件必须首先以 .html 格式保存,然后您可以使用 CTRL-K CTRL-C发表评论,它的工作原理。

Hope that help you

希望能帮到你

回答by Lucas Vi?als

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:

如果您不想禁用/卸载任何插件,您可以创建一个片段来发表评论。例如,我创建了一个在 PHP 文件中添加 HTML 注释的代码段:

    "comment HTML": {
      "prefix": "chtml",
      "body": ["<!--  -->"],
      "description": "Comment HTML line"
    }

You can insert that right after the comment in File > Preferences > User Snippets > {YourExtension}

您可以在“文件”>“首选项”>“用户代码段”>“{YourExtension}”中的评论后立即插入该内容

Then, when you start typing 'chtml' in that kind of files, IntelliSense will prompt that snippet.

然后,当您开始在此类文件中键入“chtml”时,IntelliSense 将提示该片段。

Maybe this is a workarround, but it works excellent for me. Hope it helps!

也许这是一种解决方法,但对我来说效果很好。希望能帮助到你!

https://code.visualstudio.com/docs/customization/userdefinedsnippets

https://code.visualstudio.com/docs/customization/userdefinedsnippets

回答by Ahmed Elkoussy

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

对我来说,它是 (Djaneiro) 扩展名,它使 html 文件默认为 django 模板,因此它导致 HTML 中的注释错误(按 ctrl + / 时)(用 {% comment %} 注释它们)

回答by Mohammed Osman

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

单击 (Ctrl + KC) 注释 html。单击 (Ctrl + KU) 取消注释 html。

回答by Swapnil G Thaware

In your Visual Studio Code windows, go to File->Preferences->Keyboard Shortcut

在 Visual Studio Code 窗口中,转到File->Preferences->Keyboard Shortcut

This will open two files beside each other like in the screenshot below:

这将打开彼此相邻的两个文件,如下面的屏幕截图所示:

enter image description here

在此处输入图片说明

here you can change or create your own shortcuts. Like I just replaced Ctrl+KUto Ctrl+/

您可以在此处更改或创建自己的快捷方式。就像我刚刚将Ctrl+KU替换为Ctrl+/

Hope this will work for you !!

希望这对你有用!!

回答by Manikanta Behera

If you are running Visual Studio Codein Mac. Then first press Cmd + k, Cmd + cimmediately after that.

如果您在Mac中运行Visual Studio Code。然后先按,然后立即按。Cmd + kCmd + c

enter image description here

在此处输入图片说明

回答by Todd V.

For others having the problem, the Tornado extension is also a culprit. I had to "disable (workspace)" one by one to find it.

对于其他有问题的人来说,Tornado 扩展也是一个罪魁祸首。我不得不一一“禁用(工作区)”才能找到它。

回答by Pawn

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

对我来说,有问题的扩展名是 Nunjucks(模板语言插件假定每个 .html 文件都是一个 nunjucks html 模板)

回答by Cengkuru Michael

Try uninstalling any python extension packs you may have installed! You can then reinstall the python extension you need individually.

尝试卸载您可能已安装的任何 python 扩展包!然后,您可以单独重新安装您需要的 python 扩展。

Chances are one of the extensions in the bundle of that extension pack is causing the issue

可能是该扩展包捆绑包中的扩展之一导致了问题