sublime Text3中Emmet插件的安装和使用

Emmet是一款高效的前端开发工具,能够显著提升HTML和CSS编写速度。通过简洁的语法,开发者可以快速生成复杂的代码结构,如创建带有类名和ID的元素、生成重复结构等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具。基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为“片段”。虽然片段能很好地推动你的生产力,但大多数的实现都有这样一个缺点:你必须先定义你的代码片段,并且不能在运行时进行拓展。Emmet把片段这个概念提高到了一个新的层次:你可以设置CSS形式的能够动态被解析的表达式,然后根据你所输入的缩写来得到相应的内容。Emmet是很成熟的并且非常适用于编写HTML/XML 和 CSS 代码的前端开发工具,但也可以用于编程语言。

使用示例:

在编辑器中输入缩写代码:ul>li*5 ,然后按下拓展键(默认为tab),即可得到代码片段:

[html]  view plain  copy
  1. <ul>  
  2.     <li></li>  
  3.     <li></li>  
  4.     <li></li>  
  5.     <li></li>  
  6.     <li></li>  
  7. </ul>  

只可惜我用了那么久的Sublime Text编辑器,竟然到今天才发现Emmet这个神插件。下面就为大家介绍一下sublime text中Emmet的安装方法:

步骤一:首先你需要为sublime text安装Package Control组件:

按Ctrl+`调出sublime text的console

粘贴以下代码到底部命令行并回车: import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installedpackagespath();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())

  1.  重启Sublime Text
  2.  在Perferences->package settings中看到package control,则表示安装成功

步骤二:使用Package Control安装Emmet插件:

  1.  按Ctrl+Shift+P命令板
  2.  输入install然后选择install Package,然后输入emmet找到 Emmet Css Snippets,点击就可以自动完成安装。

使用方法

emmet的使用方法也非常简单,以sublime text为例,直接在编辑器中输入HTML或CSS的代码的缩写,然后按tab键就可以拓展为完整的代码片段。(如果与已有的快捷键有冲突的话,可以自行在编辑器中将拓展键设为其他快捷键)

语法:

后代:>

缩写:nav>ul>li

[html]  view plain  copy
  1. <nav>  
  2.     <ul>  
  3.         <li></li>  
  4.     </ul>  
  5. </nav>  
兄弟:+

缩写:div+p+bq

[html]  view plain  copy
  1. <div></div>  
  2. <p></p>  
  3. <blockquote></blockquote>  
上级:^

缩写:div+div>p>span+em^bq

[html]  view plain  copy
  1. <div></div>  
  2. <div>  
  3.     <p><span></span><em></em></p>  
  4.     <blockquote></blockquote>  
  5. </div>  

缩写:div+div>p>span+em^^bq

[html]  view plain  copy
  1. <div></div>  
  2. <div>  
  3.     <p><span></span><em></em></p>  
  4. </div>  
  5. <blockquote></blockquote>  
分组:()

缩写:div>(header>ul>li*2>a)+footer>p

[html]  view plain  copy
  1. <div>  
  2.     <header>  
  3.         <ul>  
  4.             <li><a href=""></a></li>  
  5.             <li><a href=""></a></li>  
  6.         </ul>  
  7.     </header>  
  8.     <footer>  
  9.         <p></p>  
  10.     </footer>  
  11. </div>  

缩写:(div>dl>(dt+dd)*3)+footer>p

[html]  view plain  copy
  1. <div>  
  2.     <dl>  
  3.         <dt></dt>  
  4.         <dd></dd>  
  5.         <dt></dt>  
  6.         <dd></dd>  
  7.         <dt></dt>  
  8.         <dd></dd>  
  9.     </dl>  
  10. </div>  
  11. <footer>  
  12.     <p></p>  
  13. </footer>  
乘法:*

缩写:ul>li*5

[html]  view plain  copy
  1. <ul>  
  2.     <li></li>  
  3.     <li></li>  
  4.     <li></li>  
  5.     <li></li>  
  6.     <li></li>  
  7. </ul>  
自增符号:$

缩写:ul>li.item$*5

[html]  view plain  copy
  1. <ul>  
  2.     <li class="item1"></li>  
  3.     <li class="item2"></li>  
  4.     <li class="item3"></li>  
  5.     <li class="item4"></li>  
  6.     <li class="item5"></li>  
  7. </ul>  

缩写:h$[title=item$]{Header $}*3

[html]  view plain  copy
  1. <h1 title="item1">Header 1</h1>  
  2. <h2 title="item2">Header 2</h2>  
  3. <h3 title="item3">Header 3</h3>  

缩写:ul>li.item$$$*5

[html]  view plain  copy
  1. <ul>  
  2.     <li class="item001"></li>  
  3.     <li class="item002"></li>  
  4.     <li class="item003"></li>  
  5.     <li class="item004"></li>  
  6.     <li class="item005"></li>  
  7. </ul>  

缩写:ul>li.item$@-*5

[html]  view plain  copy
  1. <ul>  
  2.     <li class="item5"></li>  
  3.     <li class="item4"></li>  
  4.     <li class="item3"></li>  
  5.     <li class="item2"></li>  
  6.     <li class="item1"></li>  
  7. </ul>  

缩写:ul>li.item$@3*5

[html]  view plain  copy
  1. <ul>  
  2.     <li class="item3"></li>  
  3.     <li class="item4"></li>  
  4.     <li class="item5"></li>  
  5.     <li class="item6"></li>  
  6.     <li class="item7"></li>  
  7. </ul>  
ID和类属性

缩写:#header

[html]  view plain  copy
  1. <div id="header"></div>  

缩写:.title

[html]  view plain  copy
  1. <div class="title"></div>  

缩写:form#search.wide

[html]  view plain  copy
  1. <form id="search" class="wide"></form>  

缩写:p.class1.class2.class3

[html]  view plain  copy
  1. <p class="class1 class2 class3"></p>  
自定义属性

缩写:p[title="Hello world"]

[html]  view plain  copy
  1. <p title="Hello world"></p>  

缩写:td[rowspan=2 colspan=3 title]

[html]  view plain  copy
  1. <td rowspan="2" colspan="3" title=""></td>  

缩写:[a='value1' b="value2"]

[html]  view plain  copy
  1. <div a="value1" b="value2"></div>  
文本:{}

缩写:a{Click me}

[html]  view plain  copy
  1. <a href="">Click me</a>  

缩写:p>{Click }+a{here}+{ to continue}

[html]  view plain  copy
  1. <p>Click <a href="">here</a> to continue</p>  
隐式标签

缩写:.class

[html]  view plain  copy
  1. <div class="class"></div>  

缩写:em>.class

[html]  view plain  copy
  1. <em><span class="class"></span></em>  

缩写:ul>.class

[html]  view plain  copy
  1. <ul>  
  2.     <li class="class"></li>  
  3. </ul>  

缩写:table>.row>.col

[html]  view plain  copy
  1. <table>  
  2.     <tr class="row">  
  3.         <td class="col"></td>  
  4.     </tr>  
  5. </table>  

HTML

所有未知的缩写都会转换成标签,例如,foo → <foo></foo>

缩写:!

[html]  view plain  copy
  1. <!doctype html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>Document</title>  
  6. </head>  
  7. <body>  
  8.   
  9. </body>  
  10. </html>  

缩写:a

[html]  view plain  copy
  1. <a href=""></a>  

缩写:a:link

[html]  view plain  copy
  1. <a href="http://"></a>  

缩写:a:mail

[html]  view plain  copy
  1. <a href="mailto:"></a>  

缩写:abbr

[html]  view plain  copy
  1. <abbr title=""></abbr>  

缩写:acronym

[html]  view plain  copy
  1. <acronym title=""></acronym>  

缩写:base

[html]  view plain  copy
  1. <base href="" />  

缩写:basefont

[html]  view plain  copy
  1. <basefont />  

缩写:br

[html]  view plain  copy
  1. <br />  

缩写:frame

[html]  view plain  copy
  1. <frame />  

缩写:hr

[html]  view plain  copy
  1. <hr />  

缩写:bdo

[html]  view plain  copy
  1. <bdo dir=""></bdo>  

缩写:bdo:r

[html]  view plain  copy
  1. <bdo dir="rtl"></bdo>  

缩写:bdo:l

[html]  view plain  copy
  1. <bdo dir="ltr"></bdo>  

缩写:col

[html]  view plain  copy
  1. <col />  

缩写:link

[html]  view plain  copy
  1. <link rel="stylesheet" href="" />  

缩写:link:css

[html]  view plain  copy
  1. <link rel="stylesheet" href="style.css" />  

缩写:link:print

[html]  view plain  copy
  1. <link rel="stylesheet" href="print.css" media="print" />  

缩写:link:favicon

[html]  view plain  copy
  1. <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />  

缩写:link:touch

[html]  view plain  copy
  1. <link rel="apple-touch-icon" href="favicon.png" />  

缩写:link:rss

[html]  view plain  copy
  1. <link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml" />  

缩写:link:atom

[html]  view plain  copy
  1. <link rel="alternate" type="application/atom+xml" title="Atom" href="atom.xml" />  

缩写:meta

[html]  view plain  copy
  1. <meta />  

缩写:meta:utf

[html]  view plain  copy
  1. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />  

缩写:meta:win

[html]  view plain  copy
  1. <meta http-equiv="Content-Type" content="text/html;charset=windows-1251" />  

缩写:meta:vp

[html]  view plain  copy
  1. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />  

缩写:meta:compat

[html]  view plain  copy
  1. <meta http-equiv="X-UA-Compatible" content="IE=7" />  

缩写:style

[html]  view plain  copy
  1. <style></style>  

缩写:script

[html]  view plain  copy
  1. <script></script>  

缩写:script:src

[html]  view plain  copy
  1. <script src=""></script>  

缩写:img

[html]  view plain  copy
  1. <img src="" alt="" />  

缩写:iframe

[html]  view plain  copy
  1. <iframe src="" frameborder="0"></iframe>  

缩写:embed

[html]  view plain  copy
  1. <embed src="" type="" />  

缩写:object

[html]  view plain  copy
  1. <object data="" type=""></object>  

缩写:param

[html]  view plain  copy
  1. <param name="" value="" />  

缩写:map

[html]  view plain  copy
  1. <map name=""></map>  

缩写:area

[html]  view plain  copy
  1. <area shape="" coords="" href="" alt="" />  

缩写:area:d

[html]  view plain  copy
  1. <area shape="default" href="" alt="" />  

缩写:area:c

[html]  view plain  copy
  1. <area shape="circle" coords="" href="" alt="" />  

缩写:area:r

[html]  view plain  copy
  1. <area shape="rect" coords="" href="" alt="" />  

缩写:area:p

[html]  view plain  copy
  1. <area shape="poly" coords="" href="" alt="" />  

缩写:form

[html]  view plain  copy
  1. <form action=""></form>  

缩写:form:get

[html]  view plain  copy
  1. <form action="" method="get"></form>  

缩写:form:post

[html]  view plain  copy
  1. <form action="" method="post"></form>  

缩写:label

[html]  view plain  copy
  1. <label for=""></label>  

缩写:input

[html]  view plain  copy
  1. <input type="text" />  

缩写:inp

[html]  view plain  copy
  1. <input type="text" name="" id="" />  

缩写:input:hidden

别名:input[type=hidden name]

[html]  view plain  copy
  1. <input type="hidden" name="" />  

缩写:input:h

别名:input:hidden

[html]  view plain  copy
  1. <input type="hidden" name="" />  

缩写:input:text, input:t

别名:inp

[html]  view plain  copy
  1. <input type="text" name="" id="" />  

缩写:input:search

别名:inp[type=search]

[html]  view plain  copy
  1. <input type="search" name="" id="" />  

缩写:input:email

别名:inp[type=email]

[html]  view plain  copy
  1. <input type="email" name="" id="" />  

缩写:input:url

别名:inp[type=url]

[html]  view plain  copy
  1. <input type="url" name="" id="" />  

缩写:input:password

别名:inp[type=password]

[html]  view plain  copy
  1. <input type="password" name="" id="" />  

缩写:input:p

别名:input:password

[html]  view plain  copy
  1. <input type="password" name="" id="" />  

缩写:input:datetime

别名:inp[type=datetime]

[html]  view plain  copy
  1. <input type="datetime" name="" id="" />  

缩写:input:date

别名:inp[type=date]

[html]  view plain  copy
  1. <input type="date" name="" id="" />  

缩写:input:datetime-local

别名:inp[type=datetime-local]

[html]  view plain  copy
  1. <input type="datetime-local" name="" id="" />  

缩写:input:month

别名:inp[type=month]

[html]  view plain  copy
  1. <input type="month" name="" id="" />  

缩写:input:week

别名:inp[type=week]

[html]  view plain  copy
  1. <input type="week" name="" id="" />  

缩写:input:time

别名:inp[type=time]

[html]  view plain  copy
  1. <input type="time" name="" id="" />  

缩写:input:number

别名:inp[type=number]

[html]  view plain  copy
  1. <input type="number" name="" id="" />  

缩写:input:color

别名:inp[type=color]

[html]  view plain  copy
  1. <input type="color" name="" id="" />  

缩写:input:checkbox

别名:inp[type=checkbox]

[html]  view plain  copy
  1. <input type="checkbox" name="" id="" />  

缩写:input:c

别名:input:checkbox

[html]  view plain  copy
  1. <input type="checkbox" name="" id="" />  

缩写:input:radio

别名:inp[type=radio]

[html]  view plain  copy
  1. <input type="radio" name="" id="" />  

缩写:input:r

别名:input:radio

[html]  view plain  copy
  1. <input type="radio" name="" id="" />  

缩写:input:range

别名:inp[type=range]

[html]  view plain  copy
  1. <input type="range" name="" id="" />  

缩写:input:file

别名:inp[type=file]

[html]  view plain  copy
  1. <input type="file" name="" id="" />  

缩写:input:f

别名:input:file

[html]  view plain  copy
  1. <input type="file" name="" id="" />  

缩写:input:submit

[html]  view plain  copy
  1. <input type="submit" value="" />  

缩写:input:s

别名:input:submit

[html]  view plain  copy
  1. <input type="submit" value="" />  

缩写:input:image

[html]  view plain  copy
  1. <input type="image" src="" alt="" />  

缩写:input:i

别名:input:image

[html]  view plain  copy
  1. <input type="image" src="" alt="" />  

缩写:input:button

[html]  view plain  copy
  1. <input type="button" value="" />  

缩写:input:b

别名:input:button

[html]  view plain  copy
  1. <input type="button" value="" />  

缩写:isindex

[html]  view plain  copy
  1. <isindex />  

缩写:input:reset

别名:input:button[type=reset]

[html]  view plain  copy
  1. <input type="reset" value="" />  

缩写:select

[html]  view plain  copy
  1. <select name="" id=""></select>  

缩写:option

[html]  view plain  copy
  1. <option value=""></option>  

缩写:textarea

[html]  view plain  copy
  1. <textarea name="" id="" cols="30" rows="10"></textarea>  

缩写:menu:context

别名:menu[type=context]>

[html]  view plain  copy
  1. <menu type="context"></menu>  

缩写:menu:c

别名:menu:context

[html]  view plain  copy
  1. <menu type="context"></menu>  

缩写:menu:toolbar

别名:menu[type=toolbar]>

[html]  view plain  copy
  1. <menu type="toolbar"></menu>  

缩写:menu:t

别名:menu:toolbar

[html]  view plain  copy
  1. <menu type="toolbar"></menu>  

缩写:video

[html]  view plain  copy
  1. <video src=""></video>  

缩写:audio

[html]  view plain  copy
  1. <audio src=""></audio>  

缩写:html:xml

[html]  view plain  copy
  1. <html xmlns="http://www.w3.org/1999/xhtml"></html>  

缩写:keygen

[html]  view plain  copy
  1. <keygen />  

缩写:command

[html]  view plain  copy
  1. <command />  

缩写:bq

别名:blockquote

[html]  view plain  copy
  1. <blockquote></blockquote>  

缩写:acr

别名:acronym

[html]  view plain  copy
  1. <acronym title=""></acronym>  

缩写:fig

别名:figure

[html]  view plain  copy
  1. <figure></figure>  

缩写:figc

别名:figcaption

[html]  view plain  copy
  1. <figcaption></figcaption>  

缩写:ifr

别名:iframe

[html]  view plain  copy
  1. <iframe src="" frameborder="0"></iframe>  

缩写:emb

别名:embed

[html]  view plain  copy
  1. <embed src="" type="" />  

缩写:obj

别名:object

[html]  view plain  copy
  1. <object data="" type=""></object>  

缩写:src

别名:source

[html]  view plain  copy
  1. <source></source>  

缩写:cap

别名:caption

[html]  view plain  copy
  1. <caption></caption>  

缩写:colg

别名:colgroup

[html]  view plain  copy
  1. <colgroup></colgroup>  

缩写:fst, fset

别名:fieldset

[html]  view plain  copy
  1. <fieldset></fieldset>  

缩写:btn

别名:button

[html]  view plain  copy
  1. <button></button>  

缩写:btn:b

别名:button[type=button]

[html]  view plain  copy
  1. <button type="button"></button>  

缩写:btn:r

别名:button[type=reset]

[html]  view plain  copy
  1. <button type="reset"></button>  

缩写:btn:s

别名:button[type=submit]

[html]  view plain  copy
  1. <button type="submit"></button>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值