zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Sublime Text自定义代码片段Code Snippets

code代码 自定义 Text Sublime 片段
2023-09-27 14:24:04 时间

Mac
菜单栏 -> Tools -> Developer -> 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>

修改第三行内容

<snippet>
    <content><![CDATA[
String ${1}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>str</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.java</scope>
</snippet>

1、${1} 进入页面后, 光标移入的位置

2、<tabTrigger>str</tabTrigger>
tab触发的标识 输入 str + tab 自动补全 为 String

3、<scope>source.java</scope>
生效文件,此处在java文件生效

4、保存文件为 str.sublime-snippet

回到java文件,输入 str + tab 自动补全 为 String

参考
sublime编辑器的一个使用小技巧: 自定义代码片段