关于 sublime snippet

sublime text 3 是真的好用啊!

snippet 可以自定义你的代码片段,也就是相当于代码补全的功能,个人感觉非常的 nice 。

首先,通过 Tools -> Developer -> New Snippet 建立一个新的程序,会出现下面代码:

1 <snippet>
2     <content><![CDATA[
3 Hello, ${1:this} is a ${2:snippet}.
4 ]]></content>
5     <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
6     <!-- <tabTrigger>hello</tabTrigger> -->
7     <!-- Optional: Set a scope to limit where the snippet will trigger -->
8     <!-- <scope>source.python</scope> -->
9 </snippet>

第 3 行是自定义的代码片段,第 6 行内填引发代码片段的字符串,在第 8 行是触发该片段的语言环境。

实例:

 1 <snippet>
 2     <content><![CDATA[
 3 #include <set>
 4 #include <map>
 5 #include <queue>
 6 #include <vector>
 7 #include <stdio.h>
 8 #include <iostream>
 9 using namespace std;
10 
11 ${1}
12 
13 int main(void)
14 {
15     ${2}
16     return 0;
17 }
18 ]]></content>
19     <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
20     <tabTrigger>start</tabTrigger>
21     <!-- Optional: Set a scope to limit where the snippet will trigger -->
22     <!-- <scope>source.python</scope> -->
23     <!-- Optional: Description to show in the menu -->
24     <description> your programming travel !</description>
25 </snippet>

补充:

在上面实例中有一些其他的东西:

1. 在第 24 行,这一段是片段说明,如果没有的话默认是文件名

2. ${一个数字} 这个的作用是现实光标的位置,通过 TAB 键来切换到下一个位置。

猜你喜欢

转载自www.cnblogs.com/A4paper/p/10341191.html
今日推荐