牙叔教程 简单易懂
什么是代码片段
snippet[ˈsnɪpɪt],或者说「code snippet」,也即代码片,指的是能够帮助输入重复代码模式,比如循环或条件语句,的模板。通过 snippet ,我们仅仅输入一小段字符串,就可以在代码片引擎的帮助下,生成预定义的模板代码,接着我们还可以通过在预定义的光标位置之间跳转,来快速补全模板。
添加代码片段
点击vscode界面左下角的齿轮,
展开菜单中点击用户代码片段,
再点击新建全局代码片段文件,
输入文件名
复制黏贴以下代码内容即可
{ // Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope // is left empty or omitted, the snippet gets applied to all languages. 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": { // "scope": "javascript,typescript", // "prefix": "log", // "body": [ // "console.log('$1');", // "$2" // ], // "description": "Log output to console" // } "loadDex": { "scope": "javascript,typescript", "prefix": "loaddex", "body": ["runtime.loadDex(\"./$1.dex\");"], "description": "加载目标dex文件,加载成功后将可以使用该dex文件的类。\n\n因为加载jar实际上是把jar转换为dex再加载的,因此加载dex文件会比jar文件快得多。可以使用Android SDK的build tools的dx工具把jar转换为dex。" }, "loadJar": { "scope": "javascript,typescript", "prefix": "loadjar", "body": ["runtime.loadJar(\"./$1.jar\");"], "description": "加载目标jar文件,加载成功后将可以使用该Jar文件的类。\n\n // 加载jsoup.jar\n runtime.loadJar(\"./jsoup.jar\");\n // 使用jsoup解析html\n importClass(org.jsoup.Jsoup);\n log(Jsoup.parse(files.read(\"./test.html\")));\n \n\n(jsoup是一个Java实现的解析Html DOM的库,可以在[Jsoup](https://jsoup.org/download)下载)" }, "for i": { "scope": "javascript,typescript", "prefix": "fori", "body": ["for(var i=0;i<10;i++){", " $1", "}"], "description": "for循环" }, "for len ": { "scope": "javascript,typescript", "prefix": "forlen", "body": ["var len = $1.length", "for(var i=0;i<len;i++){", " $2", "}"], "description": "for循环" }, "view find ": { "scope": "javascript,typescript", "prefix": "viewfind", "body": [ "let view = idEndsWith(appInterfaceInformation.XXX$1XXX).visibleToUser(true).boundsInside(0, 0, device.width, device.height).findOne();" ], "description": "viewfind" }, "left top ": { "scope": "javascript,typescript", "prefix": "lefttop", "body": [ "let viewBounds = view.bounds();", "let left = viewBounds.left;", "let top = viewBounds.top;", "let right = viewBounds.right;", "let bottom = viewBounds.bottom;", "let centerX = viewBounds.centerX();", "let centerY = viewBounds.centerY();", "let width = viewBounds.width();", "let height = viewBounds.height();" ], "description": "lefttop" }, "logobj": { "scope": "javascript,typescript", "prefix": "logobj", "body": ["console.log(\"$1 =\");", "console.log($1);"], "description": "lefttop" }, "autojs ui ": { "scope": "javascript,typescript", "prefix": "ajui", "body": ["\"ui\";", "ui.layout(", " <vertical>", " $1", " </vertical>", ")"], "description": "lefttop" } }
用户自定义的代码片段所在文件夹
C:\Users\Administrator\AppData\Roaming\Code\User\snippets
关闭vscode自带的代码提示功能
设置中搜索 editor.acceptSuggestionOnCommitCharacter , 取消勾选即可.
一般不需要关闭, 除非你觉得自带的提示比较智障, 并且已经用插件
Tabnine Autocomplete AI
或者
Kite AutoComplete AI Code
训练好代码自动补全.
参考
跟我一起在Visual Studio Code 添加自定义snippet
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问
--- 牙叔教程
声明
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途