添加id =""的快捷方式和班级="" Sublime Text 2中的HTML标签

时间:2015-02-10 21:18:23

标签: html css sublimetext2 shortcuts

如何设置Sublime Text 2,以便输入 .(句号)生成class=" " #(哈希)生成{输入一个开头的HTML代码时会发现{1}} 吗?

4 个答案:

答案 0 :(得分:8)

键入foo.bar,按Tab键,您将获得

<foo class="bar"></foo>

还有foo #bar(用于id而不是class)。两者都在Packages / HTML / html_completions.py

中实现

答案 1 :(得分:6)

我找到了答案。转到:首选项 - &gt;设置 - &gt;用户。

在花括号之间添加以下文字,然后保存文件:

"auto_id_class": true,

这样,您只需输入id=" "class=" "

,即可快速将#.添加到HTML标记中

如果您使用sublime文本,这是一个很好的功能。

答案 2 :(得分:4)

查看http://emmet.io/,它是一个帮助html和css的sublime插件。

例如:

.class

变为

<div class="class"></div>

可以找到更多示例here

答案 3 :(得分:0)

我正在使用ST3,但是"auto_id_class": true, @Paul_S答案)对我不起作用。相反,我快速创建了一个自定义代码段。查看下面的代码段。注意:范围<scope>meta.tag.other.html, meta.tag.block.any.html, meta.tag.inline.any.html</scope>可能会更好/更完善,但由于它对我有用,因此不必费心进行进一步的研究。

ID

<snippet>
    <content><![CDATA[
id="${1}"
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>#</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>meta.tag.other.html, meta.tag.block.any.html, meta.tag.inline.any.html</scope>
</snippet>

课程

<snippet>
    <content><![CDATA[
class="${1}"
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>.</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>meta.tag.other.html, meta.tag.block.any.html, meta.tag.inline.any.html</scope>
</snippet>

谢谢