在Sublime Text 3中添加snippet

1,点击Tools->New Snippet,你会得到如下代码

<snippet>
    <content><![CDATA[
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>

参数讲解:

  [CDATA['这里是你要现实的内容']]

    你所需要显示的内容都要写在CDATA[]中

 

  ${1:text}

    这里的数字1,代表光标第一显示的位置,必选,你还可以设置更多,${2:text}光标第二显示的位置,按tab键由1位置到2位置,${100:text}光标第100显示的位置

    text代表默认替代文字,可选

      

     

  <tabTrigger>hello</tabTrigger>
这里的hello代表触发的表达式,也就是当你输入hello会触发这个snippet,记得要解除这句话的注释,删掉<!-- -->
  
  <scope>source.python</scope>

    这里的.python代表触发的文件格式,也就是只有你在编辑python文件时才会起作用,同理可以添加<scope>source.python.php</scope>等等,我通常会注释掉这句话
 

下面举个简单例子

<snippet>
    <content><![CDATA[console.log("${1}");]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>con</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

这是我写的 一个用来快速添加console.log()的snippet,当我输入con的时候,看到提示列表后,按enter   (这里的hello后面讲)

我们看最关键的一行

<content><![CDATA[console.log("${1}");]]></content>

这里的

console.log("${1}");

就是我要插入显示的内容,${1},意味着光标第一个所在的位置,效果就是当整个内容查到你写的文档中的时候,光标默认在两个引号中间

如果这里我写成${1:text},就表示光标替代处的内容是text,默认text是选中状态

console.log("text");

 

效果如图

还可以添加更多的${n:text}按tab键切换位置

例如

<content><![CDATA[console.log("${1:text}");${20:tttt}]]></content>

 

 效果是

单击一次tab之后

 

最后,但文件编辑完成 我们保存为hello.sublime-snippet,这就是前面的hello的原因

保存路径是C:\Users\zhangsan\AppData\Roaming\Sublime Text 3\Packages\User

zhangsan是你的电脑用户名

如果你写成console.log().sublime-snippet,就是这样

ok 打完收工

转载于:https://www.cnblogs.com/geqianst/p/3689425.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值