Sublime 代码段设置
# Sublime 代码段
> 依次找到: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>配置文件是 XML 格式,含义如下:
- snippet: 父节点,必须
- content: 内容节点,将要定义的代码段写到该节点下
- tabTrigger: 触发节点,设置触发源
- scope: 代码段生效作用域
- ${number:}: Tab 按键切换的光标
下面是一个 Demo:
<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>接下来 Ctrl + s 保存该文件,写入文件名:hello.sublime-snippet , 然后到文件中通过输入 hello 触发给代码段。
注意:最后保存文件的时候,必须是 xxx.sublime-snippet 的名字保存,其中 xxx 替换成你自己定义的名字。

浙公网安备 33010602011771号