Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sublime Snippet 代码段 #20

Open
pfan123 opened this issue Sep 7, 2017 · 0 comments
Open

Sublime Snippet 代码段 #20

pfan123 opened this issue Sep 7, 2017 · 0 comments

Comments

@pfan123
Copy link
Owner

pfan123 commented Sep 7, 2017

依次找到: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 替换成你自己定义的名字。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant