Sublime Text 2之Emmet插件安装及使用

1.安装Emmet

How To Install?Reffer to this link:http://www.ituring.com.cn/article/47310

2.使用Emmet--Abbreviations Syntax

Emmet uses syntax similar to CSS selectors for describing elements’ positions inside generated tree and elements’ attributes.

Elements

You can use elements’ names like div or p to generate HTML tags. Emmet doesn’t have a predefined set of available tag names, you can write any word and transform it into a tag: div → <div></div>foo → <foo></foo> and so on.

Nesting operators

Nesting operators are used to position abbreviation elements inside generated tree: whether it should be placed inside or near the context element.

Child: >

You can use > operator to nest elements inside each other:

div>ul>li

...will produce

<div>
    <ul>
        <li></li>
    </ul>
</div>

Sibling: +

Use + operator to place elements near each other, on the same level:

div+p+bq

...will output

<div></div>
<p></p>
<blockquote></blockquote>

Climb-up: ^

With > operator you’re descending down the generated tree and positions of all sibling elements will be resolved against the most deepest element:

div+div>p>span+em 

...will be expanded to

<div></div>
<div>
    <p><span></span><em></em></p>
</div>

With ^ operator, you can climb one level up the tree and change context where following elements should appear:

div+div>p>span+em^bq

...outputs to

<div></div>
<div>
    <p><span></span><em></em></p>
    <blockquote></blockquote>
</div>

You can use as many ^ operators as you like, each operator will move one level up:

div+div>p>span+em^^^bq

...will output to

<div></div>
<div>
    <p><span></span><em></em></p>
</div>
<blockquote></blockquote>

Multiplication: *

With * operator you can define how many times element should be outputted:

ul>li*5

...outputs to

<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

Grouping: ()

Parenthesises are used by Emmets’ power users for grouping subtrees in complex abbreviations:

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

...expands to

<div>
    <header>
        <ul>
            <li><a href=""></a></li>
            <li><a href=""></a></li>
        </ul>
    </header>
    <footer>
        <p></p>
    </footer>
</div>

If you’re working with browser’s DOM, you may think of groups as Document Fragments: each group contains abbreviation subtree and all the following elements are inserted at the same level as the first element of group.

You can nest groups inside each other and combine them with multiplication * operator:

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

...produces

<div>
    <dl>
        <dt></dt>
        <dd></dd>
        <dt></dt>
        <dd></dd>
        <dt></dt>
        <dd></dd>
    </dl>
</div>
<footer>
    <p></p>
</footer>

With groups, you can literally write full page mark-up with a single abbreviation, but please don’t do that.

Attribute operators

Attribute operators are used to modify attributes of outputted elements. For example, in HTML and XML you can quickly add class attribute to generated element.

ID and CLASS

In CSS, you use elem#id and elem.class notation to reach the elements with specified id or classattributes. In Emmet, you can use the very same syntax to add these attributes to specified element:

div#header+div.page+div#footer.class1.class2.class3

...will output

<div id="header"></div>
<div class="page"></div>
<div id="footer" class="class1 class2 class3"></div>

Custom attributes

You can use [attr] notation (as in CSS) to add custom attributes to your element:

td[title="Hello world!" colspan=3]

...outputs

<td title="Hello world!" colspan="3"></td>
  • You can place as many attributes as you like inside square brackets.
  • You don’t have to specify attribute values: td[colspan title] will produce <td colspan="" title=""> with tabstops inside each empty attribute (if your editor supports them).
  • You can use single or double quotes for quoting attribute values.
  • You don’t need to quote values if they don’t contain spaces: td[title=hello colspan=3] will work.

Item numbering: $

With multiplication * operator you can repeat elements, but with $ you can number them. Place $ operator inside element’s name, attribute’s name or attribute’s value to output current number of repeated element:

ul>li.item$*5

...outputs to

<ul>
    <li class="item1"></li>
    <li class="item2"></li>
    <li class="item3"></li>
    <li class="item4"></li>
    <li class="item5"></li>
</ul>

You can use multiple $ in a row to pad number with zeroes:

ul>li.item$$$*5

...outputs to

<ul>
    <li class="item001"></li>
    <li class="item002"></li>
    <li class="item003"></li>
    <li class="item004"></li>
    <li class="item005"></li>
</ul>

Changing numbering base and direction

With @ modifier, you can change numbering direction (ascending or descending) and base (e.g. start value).

For example, to change direction, add @- after $:

ul>li.item[email protected]*5

…outputs to

<ul>
    <li class="item5"></li>
    <li class="item4"></li>
    <li class="item3"></li>
    <li class="item2"></li>
    <li class="item1"></li>
</ul>

To change counter base value, add @N modifier to $:

ul>li.item[email protected]3*5

…transforms to

<ul>
    <li class="item3"></li>
    <li class="item4"></li>
    <li class="item5"></li>
    <li class="item6"></li>
    <li class="item7"></li>
</ul>

You can use these modifiers together:

ul>li.item[email protected]3*5

…is transformed to

<ul>
    <li class="item7"></li>
    <li class="item6"></li>
    <li class="item5"></li>
    <li class="item4"></li>
    <li class="item3"></li>
</ul>

Text: {}

You can use curly braces to add text to element:

a{Click me}

...will produce

<a href="">Click me</a>

Note that {text} is used and parsed as a separate element (like, divp etc.) but has a special meaning when written right after element. For example, a{click} and a>{click} will produce the same output, buta{click}+b{here} and a>{click}+b{here} won’t:

<!-- a{click}+b{here} -->
<a href="">click</a><b>here</b>

<!-- a>{click}+b{here} -->
<a href="">click<b>here</b></a>

In second example the <b> element is placed inside <a> element. And that’s the difference: when {text} is written right after element, it doesn’t change parent context. Here’s more complex example showing why it is important:

p>{Click }+a{here}+{ to continue}

...produces

<p>Click <a href="">here</a> to continue</p>

In this example, to write Click here to continue inside <p> element we have explicitly move down the tree with > operator after p, but in case of a element we don’t have to, since we need <a> element with here word only, without changing parent context.

For comparison, here’s the same abbreviation written without child > operator:

p{Click }+a{here}+{ to continue}

...produces

<p>Click </p>
<a href="">here</a> to continue

Notes on abbreviation formatting

When you get familiar with Emmet’s abbreviations syntax, you may want to use some formatting to make your abbreviations more readable. For example, use spaces between elements and operators, like this:

(header > ul.nav > li*5) + footer

But it won’t work, because space is a stop symbol where Emmet stops abbreviation parsing.

Many users mistakenly think that each abbreviation should be written in a new line, but they are wrong: you can type and expand abbreviation anywhere in the text:

点击观看Demo视频

This is why Emmet needs some indicators (like spaces) where it should stop parsing to not expand anything that you don’t need. If you’re still thinking that such formatting is required for complex abbreviations to make them more readable:

  • Abbreviations are not a template language, they don’t have to be “readable”, they have to be “quickly expandable and removable”.
  • You don’t really need to write complex abbreviations. Stop thinking that “typing” is the slowest process in web-development. You’ll quickly find out that constructing a single complex abbreviation is much slower and error-prone than constructing and typing a few short ones.

refference:http://docs.emmet.io/abbreviations/syntax/

时间: 2024-07-28 20:37:34

Sublime Text 2之Emmet插件安装及使用的相关文章

Sublime Text 2的Emmet插件使用简介

Sublime Text 2的Emmet插件使用简介 Sublime Text可以说是最好用的一个文本编辑器,特别是对于广大码农朋友来说,尤其是前端码农朋友来说.关于Sublime Test的好处我就不多说了,自己去下载吧.相信会用Sublime Text的用户也一定安装了它的包管理器,那么我今天在这里重点介绍一下Emmet这个插件. 1. 快速创建HTML文档 <!-- html:5 + `tab` 或者 `!` + `tab` --> <!DOCTYPE html> <h

史上最全的 Sublime Text 汉化、插件安装合集

0.前言 本文用于给新手小白用户指明前进方向.不用做商业推广. 其次,鼓舞购买正版.拒绝盗版. 好了.口号喊完,接下来就直接開始正文. 1. Sublime Text 介绍 首先在開始前,先来介绍一下 Sublime Text. Sublime Text 是一个代码编辑器(Sublime Text 2是收费软件.但能够无限期试用),也是HTML和散文先进的文本编辑器. Sublime Text是由程序猿Jon Skinner于2008年1月份所开发出来,它最初被设计为一个具有丰富扩展功能的Vim

Sublime ctags 函数跳转插件安装

Sublime Text安装插件的方法,主要有以下两种: 1. 直接通过下载安装包安装 在编辑器菜单中点击“Preferences”–“Browse Packages…”打开插件安装目录,然后把下载的安装包解压后放到该目录即可(可能需要重启编辑器后才生效). 2.首先安装 package control 安装方法 https://packagecontrol.io/installation 里面有详细的安装方法  ,使用快捷键ctrl+` 按照里面的方法即可安装. 另外一种直接在网站下载: 手动

Sublime Text 中使用Git插件连接GitHub

sublime Text的另一个强大之处在于它提供了非常丰富的插件,可以帮助程序员来适合大多数语言的开发.这些插件通过它自己的Package Controll(包管理)组件来安装,非常方便.一般常用的插件包括: Zen Coding -- 一种快速编写HTML/CSS代码的方法JQuery package -- jQuery的代码包,jQuery的自动不全功能给jQuery程序员带来极大的方便.JS Format -- JS的格式化工具JsMinifier -- JS的压缩工具,基于Google

sublime text 3 语法检查插件

第一种方法:有点卡 先去下载对应的开发环境,安装到本地,例如php. 从Pakage Control中安装sublimelinter和sublimelinter-*,*为所用的语言,例如sublimelinter-php,不需要做其他配置,直接即可使用. 这下各种方便,可以丢弃ide了. 第二种方法: 在编译系统增加 { "cmd": ["php","-l","$file"],} 相查就查,轻松+愉快,还不卡界面 sublim

px值转rem值的Sublime Text 3自动完成插件

一个CSS的px值转rem值的Sublime Text 3自动完成插件. 插件效果如下: 安装 克隆项目   https://github.com/hyb628/cssrem.git 进入packages目录:Sublime Text -> Preferences -> Browse Packages... 复制下载的cssrem目录到刚才的packges目录里. 重启Sublime Text. 配置参数 参数配置文件:Sublime Text -> Preferences ->

Sublime Text 3 配置 PHPCS 插件

Download php code sniffer addon via Package Control in ST3. Download The php-cs-fixer File From This Website => cs.sensiolabs.org/ (Direct Link => cs.sensiolabs.org/get/php-cs-fixer.phar) Copy Downloaded File To Your php.exe directory (mine is C:/XA

Sublime Text 3之Package Control 安装

1.通过快捷键 ctrl+` 或者 View > Show Console 打开控制台,然后粘贴以下安装代码: import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler

sublime text 3中emmet常用技巧

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>sublime text 3中emmet常用技巧</title> </head> <body> <!-- 生成html5格式文件先把文件保存成.html格式,然后输入html:5按下tab键 --> <!-- 简写d