SublimeSublime Text

Sublime Text3—Code Snippets(自定义代

2017-09-21  本文已影响131人  easyblue

摘要

程序员总是会不断的重复写一些简单的代码片段,为了提高编码效率,我们可以把经常用到的代码保存起来再调用。

平时用sublime安装各种插件,使用Tab键快速补全,便是snippets(可译为代码片段)的一种。

Sublime编辑器还提供了自定义代码片段的功能(当然不止Sublime有此功能),其官方文档中定义如下:

Whether you are coding or writing the next vampire best-seller, you’re likely to need certain short fragments of text again and again. Use snippets to save yourself tedious typing. Snippets are smart templates that will insert text for you and adapt it to their context.

一、创建snippets

1. 新建和保存

<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>

2. content

3. tabTrigger

4. scope

5. description

6. 设置光标位置Fields

<snippet>
    <content><![CDATA[
First Name: $1
Second Name: $2
Address: $3
]]></content>

7. 镜像域Mirrored Fields

8. 占位符Placeholders

如默认的代码片段Hello, ${1:this} is a ${2:snippet}.会依次循环选中单词this snippet

二、使用snippets

三、安装snippets

参考

掘金:Sublime Text3—Code Snippets(自定义代码片段)
简书:Sublime Text3—Code Snippets(自定义代码片段)
博客园:Sublime Text3—Code Snippets(自定义代码片段)

上一篇下一篇

猜你喜欢

热点阅读