Sublime Text自定义snippet
程序员文章站
2024-03-23 20:58:04
...
个人环境:
win7 64位专业版 + Sublime Text3(以下简称ST)
snippet可以理解为代码片段, 在自定义好snippet后就可以快带生成相应的代码片段.
先来感受下效果:
如何编写自己的snippet呢?
在ST中: 依次选择tools -> Developer -> New Snippet
, 就打开默认的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>
其中的content
中的CDATA
就是实际的snippet的内容. tabTrigger
就是触发snippet的字符串, 比如上图中的html5
. scope
就是说在哪里会触发, 可以简单理解为文件类型.
下面是上图中的snippet写法:
<snippet>
<content><![CDATA[
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="email=no">
<title>${1}</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
${2}
</body>
</html>
]]></content>
<tabTrigger>html5</tabTrigger>
<scope>text.html</scope>
</snippet>
可以看到上面有个${1}
, ${2}
, 很容易猜到, 这就是按tab键时,光标依次停留的位置.
注意事项:
- 保存snippet时, 文件扩展名要是
sublime-snippet
.
参考:
欢迎补充指正!
推荐阅读
-
Sublime Text自定义snippet
-
OSX shell 添加sublime text 启动命令
-
sublime text3 解决中文乱UTF -8
-
sublime text 3相关配置
-
Sublime Text 3 调教你的私人利器(上)
-
Sublime Text插件的离线安装-使用htmlprettify美化您的HTML代码 Sublime TexthtmlJavaScriptprettify
-
Sublime Text 2 使用心得 博客分类: Sublime Text2 Sublime Text2
-
Sublime Text 2 使用心得 博客分类: Sublime Text2 Sublime Text2
-
沐枫凌-python 新手教学(附加1)--学会在Sublime Text 3中编写python之安装与配置
-
Sublime Text 3 配置 博客分类: 杂项 Sublime Text配置