[英]Shortcut for adding id=“” and class=“” to HTML tags in Sublime Text 2
How do you set up Sublime Text 2 so that typing a .
你如何设置 Sublime Text 2 以便输入
.
(period) produces class=" "
and #
(hash) produces id=" "
when typing an opening HTML tag? (句号)在输入一个打开的 HTML 标签时产生
class=" "
和#
(hash)产生id=" "
?
Type foo.bar, press Tab, and you'll get输入 foo.bar,按 Tab,你会得到
<foo class="bar"></foo>
There's also foo#bar (for id instead of class).还有 foo#bar (用于 id 而不是类)。 Both are implemented in Packages/HTML/html_completions.py
两者都在 Packages/HTML/html_completions.py 中实现
I found the answer.我找到了答案。 Go to: Preferences -> Setting -> User.
转到:首选项 -> 设置 -> 用户。
add the following text between the curly braces, then save the file:在大括号之间添加以下文本,然后保存文件:
"auto_id_class": true,
this allows you to add id=" "
and class=" "
into HTML tags quickly, just by typing a #
or .
这允许您快速将
id=" "
和class=" "
到 HTML 标签中,只需键入#
或.
If you use sublime text it's a nice feature.如果您使用 sublime 文本,这是一个不错的功能。
Check out http://emmet.io/ , its a plugin for sublime that helps with html and css.查看http://emmet.io/ ,它是一个 sublime 插件,有助于处理 html 和 css。
For example:例如:
.class
becomes变成
<div class="class"></div>
I am using ST3 but "auto_id_class": true,
( @Paul_S answer ) did not work for me.我正在使用 ST3,但
"auto_id_class": true,
( @Paul_S 答案)对我不起作用。 Instead I created a custom snippet quickly.相反,我快速创建了一个自定义片段。 Check out snippet below.
看看下面的片段。 Note: the scope
<scope>meta.tag.other.html, meta.tag.block.any.html, meta.tag.inline.any.html</scope>
could be better/further refined but since it worked for me so didn't bother researching further.注意:范围
<scope>meta.tag.other.html, meta.tag.block.any.html, meta.tag.inline.any.html</scope>
可以更好/进一步完善,但因为它对我<scope>meta.tag.other.html, meta.tag.block.any.html, meta.tag.inline.any.html</scope>
所以没有费心进一步研究。
ID 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>
Class班级
<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>
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.