在文件崇高文本2中使用宏功能

时间:2014-01-07 00:18:25

标签: macros sublimetext2

假设有一个我想要使用的宏,它会为我当前的文件添加一个标题。 是否有插件允许我声明一个宏并在文本中使用它?

示例:

Macroname:css title

Callerid:!cssTitle

所以当我输入!cssTitle到我的文件并点击输入时,显示:

/*------------------------------------*\
[Insert Title]
\*------------------------------------*/
/*
[Insert section title]  [Insert description]
*/

1 个答案:

答案 0 :(得分:1)

我强烈建议您使用build in snippet功能。它允许您在不安装其他插件的情况下执行您刚才需要的任何操作。

Sublime text>工具>新代码段:

<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[
/*------------------------------------*\
[$1] Insert Title
\*------------------------------------*/
/*
[$2] Insert section title  [$3] Description
*/
]]>
</content>
<tabTrigger>!cssTitle</tabTrigger>
<scope>text/css</scope>
</snippet>

当然,您可以根据需要随意更改它。此外,<scope />也不是必需的。如果您愿意,可以将其删除。

另存为&gt; cssTitle.sublime.snippet

Sublime Text 2&gt;套餐&gt; CSS&gt; (保存在这里)。