vscode 代码片段 php.json
1.设置-》用户代码片段-》新建全局代码片段文件-》php.json
{ // Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the // same ids are connected. // Example: // "Print to console": { // "prefix": "log", // "body": [ // "console.log('$1');", // "$2" // ], // "description": "Log output to console" // } "public": { "prefix": "public", "body": [ "public function $1($2):$3", "{", " $4", "}" ], "description": "Log output to console" }, "protected": { "prefix": "protected", "body": [ "protected function $1($2):$3", "{", " $4", "}" ], "description": "Log output to console" }, "private": { "prefix": "private", "body": [ "private function $1($2):$3", "{", " $4", "}" ], "description": "Log output to console" }, "static": { "prefix": "static", "body": [ "public static function $1($2):$3", "{", " $4", "}" ], "description": "Log output to console" }, "foreach": { "prefix": "foreach", "body": [ "foreach($1 as \\$key=>\\$item){", " $2", "}" ], "description": "Log output to console" }, "if": { "prefix": "if", "body": [ "if($1){", " $2", "}" ], "description": "Log output to console" }, "startTrans": { "prefix": "startTrans", "body": [ "Db::startTrans();", "try {", " $1", " // 提交事务", " Db::commit();", "} catch (\\Exception \\$e) {", " // 回滚事务", " Db::rollback();", " throwError(\\$e->getMessage());", "}", "return true;", ], "description": "Log output to console" }, "transaction": { "prefix": "transaction", "body": [ "transaction(function () use ($1) {", " $2", "});", ], "description": "Log output to console" }, }
2.在设置中搜索到editor.snippetSuggestions这个设置,其中有四个选项top、bottom、inline、none四个选项,选择top即可
作用:使用户自定义的代码片段在提示的最上面
分类:
PHP
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2016-01-02 checkbox属性checked="checked"通过js已设置,但是不勾选