Visual Studio代码:如何制作插入代码段

问题描述 投票:0回答:2

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

我试图在php.json片段文件中在VSC中重新创建它:

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

问题是该片段不会显示,除非我已经在php标签内,这种方式会失败。

将代码段添加到HTML文件却无济于事。

有什么方法可以按照我想要的方式完成这项工作吗?

php visual-studio-code code-snippets
2个回答
0
投票

尝试将此添加到global.code-snippets

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

0
投票

尝试这样做去file > preferences > user snippet然后select New Global Snippets file你被要求保存.code-snippets扩展文件for the name of the file is free up to you并输入你的代码片段配置,作为一个例子

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

并保存您的文件ENJOY

© www.soinside.com 2019 - 2024. All rights reserved.