简体   繁体   English

HTML 文件中的 Visual Studio 代码注释

[英]Visual studio code comment in HTML files

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 文件中获得正确类型的注释呢?

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 模板引擎),这导致了评论问题。

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希望能帮到你

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": ["<!-- $1 -->"],
      "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

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

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:这将打开彼此相邻的两个文件,如下面的屏幕截图所示:

在此处输入图片说明

here you can change or create your own shortcuts.您可以在此处更改或创建自己的快捷方式。 Like I just replaced Ctrl+KU to Ctrl+/就像我刚刚将Ctrl+KU替换为Ctrl+/

Hope this will work for you !!希望这对你有用!!

List of extensions known to cause this unwanted behavior (Based on my own experience and other answers):已知会导致这种不需要的行为的扩展列表(基于我自己的经验和其他答案):

  • Hugo Language and Syntax Support Hugo 语言和语法支持
  • Djaneiro贾内罗
  • Nunjucks修女
  • Tornado龙卷风
  • Sublime Babel崇高的通天塔
  • Babel通天塔
  • Twig树枝
  • Django by Baptiste Darthenay (v1.0.0) 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).禁用扩展程序后,您可能需要重新启动代码(我这样做了)。

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

Click (Ctrl + KC) to comment the html.单击 (Ctrl + KC) 注释 html。 Click (Ctrl + KU) to uncomment html.单击 (Ctrl + KU) 取消注释 html。

For others having the problem, the Tornado extension is also a culprit.对于其他有问题的人来说,Tornado 扩展也是一个罪魁祸首。 I had to "disable (workspace)" one by one to find it.我不得不一一“禁用(工作区)”才能找到它。

Try uninstalling any python extension packs you may have installed!尝试卸载您可能已安装的任何 python 扩展包! You can then reinstall the python extension you need individually.然后,您可以单独重新安装您需要的 python 扩展。

Chances are one of the extensions in the bundle of that extension pack is causing the issue可能是该扩展包捆绑包中的扩展之一导致了问题

If you are running Visual Studio Code in Mac . 如果您在Mac中运行Visual Studio Code Then first press Cmd + k , Cmd + c immediately after that. 然后,首先紧接着按Cmd + kCmd + c

在此处输入图片说明

For me, this was caused by the Sublime Babel extension.对我来说,这是由 Sublime Babel 扩展引起的。 Disabling it and restarting VS Code fixed the issue: Cmd+K, Cmd+C works again, as does Cmd+/ for toggling.禁用它并重新启动 VS Code 解决了这个问题: Cmd+K, Cmd+C再次起作用, Cmd+/用于切换也是如此。 Also, HTML comment blocks are now correctly styled again.此外,HTML 注释块现在再次正确设置样式。

You can configure the file type at the bottom right corner.您可以在右下角配置文件类型。 you probably are on Django HTML.您可能正在使用 Django HTML。 you can set it to HTML.您可以将其设置为 HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM