在 Sublime Text 3 中设定自身的指令精彩片段
敲代码的情况下,常常会在注解里写一下创作者,建立時间这些,这样子也算留有了自个的印痕,今日就教各位怎样搭建自身的注解代码块(Snippets)。
Sublime Snippets(编码精彩片段)
Sublime text 3 Snippets就是你必须不断键入同样精彩片段的文字、编码时需用的关键作用。
Snippets可以存储在一切一个包的文件夹名称下,可是为了更好地简易,如今提议先储存在Packages/User文件目录下
Snippets的格式文件是.sublime-snippet,通常Snippet的构造如下所示
<snippet> <content><![CDATA[Type your snippet here]]></content> <!-- Optional: Tab trigger to activate the snippet --> <tabTrigger>xyzzy</tabTrigger> <!-- Optional: Scope the tab trigger will be active in --> <scope>source.python</scope> <!-- Optional: Description to show in the menu --> <description>My Fancy Snippet</description> </snippet>
大家只需把CDATA中的具体内容换成自身的,就可以进行一个比较简单的Snippets的撰写。
建立自身的Snippets
下面咱们就以自已的代码注释为例子,写一个Snippet。
最先,在sublime工具栏中挑选Tools | Developer | New Snippets…,随后键入
<snippet> <content><![CDATA[ /* * @author: ManiaU * @createTime: ${1:time} * @description: ${2:description} */ ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>comm</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.js</scope> </snippet>
在其中content为Snippet的具体内容,tabTrigger就是你键入哪些信息时可以鉴别为Snippet,scope的表明起效的文档方式,content中 ${}给你键入完以后,tab键可以选定的具体内容,${1:}给你键入完以后立即选定,${2:}为按一次tab选定的具体内容,以此类推。
接着储存为comment.sublime-snippet,下面随意在一个js文件中,键入comm,按住tab电脑键盘,你的Snippet就产生了。
時间键入软件
Snippet尽管转化成了,可是時间或是沒有拿下,下面就建立自身的软件,在sublime工具栏中挑选Tools | Developer | New Plugin…,键入以下几点
import sublime, sublime_plugin from time import localtime, strftime class InsertDatetimeCommand(sublime_plugin.TextCommand): def run(self, edit): sel = self.view.sel(); for s in sel: self.view.replace(edit, s, strftime("%Y-%m-%d, %H:%M:%S GMT%z", localtime()))
储存为insert_datetime.py,随后在Preference | Key Bindings中再加上
{ "keys": ["super ctrl t"], "command": "insert_datetime" }
这表明你按住⌘ Control T,就可以插进時间了,相互配合上边的Snippet,插进注解后,再加上時间和叙述,就可以便捷地产生自身的注解,如下所示
/* * @author: ManiaU * @createTime: 2017-03-14, 22:33:00 GMT 0800 * @description: This is a test! */
续篇
自然,Snippets的用途不仅如此,你能在你的条件下配备各式各样的精彩片段,可以极大提高的工作效能,大伙儿一起去探寻吧!
以上只是教你怎样在Sublime3中设定自身的指令精彩片段的详尽具体内容,大量请关心自学java网其他相关文章!
WWW.lllT.neT声明:有的资源来自网络转载,版权归原作者所有,如有侵犯到您的权益请联系邮箱:our333@126.com我们将配合处理!
原文地址:教你怎样在Sublime3中设定自身的指令精彩片段发布于2021-12-05 19:45:01