Sublime Text自定义snippet

Sublime Text自定义snippet

snippet可以理解为代码片段, 在自定义好snippet后就可以快带生成相应的代码片段

在ST中: 依次选择tools -> Developer -> New Snippet, 就打开默认的snippet了:

其中的content中的CDATA就是实际的snippet的内容. 
tabTrigger就是触发snippet的字符串, 比如html5
scope就是说在哪里会触发, 可以简单理解为文件类型.

下面是上图中的snippet写法:

<snippet> <content><![CDATA[ <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="email=no"> <title>${1}</title> <link rel="stylesheet" href="index.css"> </head> <body> ${2} </body> </html> ]]></content> <tabTrigger>html5</tabTrigger> <scope>text.html</scope> </snippet>

可以看到上面有个${1}${2}, 就是按tab键时,光标依次停留的位置.

注意事项:

  • 保存snippet时, 文件扩展名要是sublime-snippet

猜你喜欢

转载自www.cnblogs.com/wyq-web/p/9381734.html