【问题标题】:Visual Studio Code: How to make a snippet for inserting <?php ?>Visual Studio Code:如何制作插入 <?php ?> 的片段
【发布时间】:2018-05-08 07:09:26
【问题描述】:

在 TextMate 中,可以键入 php&lt;tab&gt; 以插入 &lt;?php | ?&gt;(使用 | here 标记光标位置)。

我正在尝试在 php.json sn-ps 文件中像这样在 VSC 中重新创建它:

"php tag": {
    "prefix": "php",
    "body": [
        "<?php $1 ?>"
    ],
    "description": "Insert <?php ?>"
}

问题在于,除非我已经在 php 标签中,否则 sn-p 不会显示出来,这有悖于目的。

将 sn-p 添加到 HTML 文件并没有帮助。

有什么方法可以让我按照我想要的方式工作吗?

【问题讨论】:

  • 你希望它在 html 文件中工作,我猜?我尝试将它放入我的 html.json 文件(用于 html sn-ps),它工作得很好。
  • 不,我希望它在 .php 文件中工作,但在 标签之外,因为这是我想要插入的内容......但似乎 php sn-ps 只工作 inside 标签,而 HTML sn-ps 仅适用于 .html 文件……
  • 我明白了,看起来像这个错误 - vscode 似乎认为它最近已修复 - github.com/Microsoft/vscode/issues/26275
  • 我不同意……不过,感谢您提供问题的链接。
  • 混合使用 HTML 和 PHP 是不好的做法。使用模板系统并将 HTML 保存在不同的文件中。

标签: php visual-studio-code code-snippets


【解决方案1】:

转到file &gt; preferences &gt; user snippet,然后转到select New Global Snippets file,系统会要求您保存.code-snippets 扩展文件,因为文件的名称由您自己决定并输入您的sn-p 配置,例如:

"php tag": {
     "prefix": "php",
     "body": [
         "<? php $1 ?>"
     ],
     "description": "Insert <?php ?>"
}

并保存您的文件

【讨论】:

    【解决方案2】:

    尝试将其添加到 global.code-sn-ps

    "PHP tag": {
            "scope": "",
            "prefix": "php",
            "body": [
                "<?php $1 ?>"
            ],
            "description": "Insert php tags"
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-03
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多