Sublime Text3 008 Snippet 自定义 代码片断

Sublime Text3 008 Snippet 自定义 代码片断
------------------------------------------------------------------------------
如果有什么不明白的,加QQ群:186970878

经常会有错字 或 语句不通的,欢迎联系本人,方便快速修正,也方便后来者阅读。

联系本人QQ: 2071551682
------------------------------------------------------------------------------
--------------------------- 自定义代码片断 ----------------------

1. 新建模板

Meun  Tools -> developer -> New Snippet...
菜单  工具  -> 插件开发  -> 新建代码片断...

---------------------------------------------------------------------------------

2.  模板保存

Ctrl+s 保存。名字随便起,但是后缀名必须是.sublime-snippet

这里命名:html5.sublime-snippet

默认保存位置:

C:UsersAdministratorAppDataRoamingSublime Text 3PackagesUser

---------------------------------------------------------------------------------

3.  修改模板

在<![CDATA[和]]>内写下你要的代码片段,注意的是代码片段要靠最左边。

<snippet>
 <content><![CDATA[
  <!DOCTYPE html>
  <html>
   <head>
    <meta charset="UTF-8">
    <title>Document
    </title>
   </head>
   <body>

   </body>
   </html>
Hello, ${1:this} is a ${2:snippet}.  这行是原来的,去掉。下面的默认不动。
]]></content>
 <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
 <!-- <tabTrigger>hello</tabTrigger> -->
 <!-- Optional: Set a scope to limit where the snippet will trigger -->
 <!-- <scope>source.python</scope> -->
</snippet>

---------------------------------------------------------------------------------

4.  设置快捷键

把下面tabTrigger标签的注释打开,中间的 hello 改成 h 就是你的快捷键。

]]></content>
 <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
 <tabTrigger>h</tabTrigger>
 <!-- Optional: Set a scope to limit where the snippet will trigger -->

 <!-- Optional: Set a scope to limit where the snippet will trigger
 设置范围以限制片段将触发的位置 -->
 <!-- <scope>source.python</scope> -->
</snippet>


---------------------------------------------------------------------------------

5.  使用保存的模板

快捷键调用模板

h + TAB(tab)

菜单 调用 模板(代码片断)

Meun  Tools -> Snippets
菜单  工具  -> 代码片断 ...

---------------------------------------------------------------------------------

保存的文件代码:

<snippet>
 <content><![CDATA[
<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>${1:杜鱼的 希望课堂}
  </title>
 </head>
 <body>
Hello,${2:主体内容}
 </body>
</html>
<!-- Hello, ${1:this} is a ${2:snippet}. -->
]]></content>
 <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
 <tabTrigger>h</tabTrigger>
 <!-- Optional: Set a scope to limit where the snippet will trigger -->
 <!-- <scope>source.python</scope> -->
 
</snippet>

---------------------------------------------------------------------------------

5.新建一个页面index.html,在 index 中输入一个h,然后按Tab键,就出现你设置的代码片段了。


代码插入了进来后,并且此时的光标停留在我们所标记的${1}位置处,

如果我们再按下Tab,那么光标就跳转到${2}的位置。

---------------------------------------------------------------------------------

------------------------------------------------------------------------------
如果有什么不明白的,加QQ群:186970878

经常会有错字 或 语句不通的,欢迎联系本人,方便快速修正,也方便后来者阅读。

联系本人QQ: 2071551682
------------------------------------------------------------------------------

原文地址:https://www.cnblogs.com/qy123/p/9190798.html