=Start=
为Golang格式的代码创建snippet片段
$ cd $HOME/Library/Application\ Support/Sublime\ Text\ 2/Packages/ $ find . -type f -iname "*.tmSnippet" $ cp ./Go/func.tmSnippet ./User/go_comment.tmSnippet $ vim ./User/go_comment.tmSnippet <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>content</key> <string>/* $0 */</string> <key>name</key> <string>Multi-line comment</string> <key>scope</key> <string>source.go</string> <key>tabTrigger</key> <string>comment</string> <key>uuid</key> <string>E9B44CC5-B004-4793-B125-7E429FDCCE99</string> </dict> </plist>
上面的内容中有几个注意事项:
1.作用范围设定为Golang代码 <string>source.go</string> 2.uuid的值需要唯一 <key>uuid</key> <string>E9B44CC5-B004-4793-B125-7E429FDCCE99</string> 3.后缀名 需要为".tmSnippet" 4.保存路径 保存路径为"$HOME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/"
参考链接:
- http://stackoverflow.com/questions/13922174/defining-scope-for-custom-sublime-text-2-snippets
- http://sublimetext.info/docs/en/extensibility/snippets.html
- http://segmentfault.com/a/1190000000488650
- https://gist.github.com/iambibhas/4705378
为Bash格式的代码创建snippet片段
在菜单上点击”Tools -> New Snippet”,会新建一个XML格式的文件,初始内容如下:
<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>
修改为:
<snippet> <content><![CDATA[#!/bin/bash # Author: ixyzero.com # Date: ${1:datetime} # set -x export PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin/:/usr/local/sbin VERBOSE="N" function func_name() { # to do : } function func_main() { func_name } func_main ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>ibash</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.shell</scope> </snippet>
注:本来想插入的snippet是功能更全的一个模板,但是,因为$1、$0这些和Bash的命令行参数冲突,并且,${BASH_SOURCE}、${LINENO}、${FUNCNAME[0]}、……等冲突,所以只能缩减为上面那样才行。
=EOF=
《 “在Sublimet Text2中创建snippet片段” 》 有 2 条评论
Sublime Text3—Code Snippets(自定义代码片段)
https://juejin.im/post/59c36c41f265da0669086225
http://docs.sublimetext.info/en/latest/extensibility/snippets.html
Sublime Text自定制代码片段(Code Snippets)
https://9iphp.com/web/html/sublime-text-code-snippets.html
Snippets
http://sublimetext.info/docs/en/extensibility/snippets.html
`
# Mac 查看当前文档所属语言类型的快捷键(‘Show Scope Name’ shortcuts)
shift + control + p
`
手把手教你写Sublime中的Snippet
https://www.jianshu.com/p/356bd7b2ea8e