zoukankan      html  css  js  c++  java
  • sublime text3 之snippet编写代码片段

    sublime text 3 中有个强大的功能就是可以编写各种文件类型的snippet代码片段,可以节省大量的时间。

    • 点击sublime text 中的工具一栏,再次点击新代码块,如下图所示

    •  会出如下图所示现默认的代码块,其中<snippet>标签里面是代码块所有的信息;<content>标签里面填写的是所需的代码片段,代码块必须包含在<![CDATA[ ]]>;<tabTrigger>标签里面是代码块别名,tab键的触发词,最好是简单易记的;<scope>标签是代码块的作用域,即作用文件类型。

    • 写个简单的例子JS文件的注释,

      <snippet>
          <content><![CDATA[
              /**
               *@des:功能详细描述
               *@author:qinbb
               *@date:日期
              */
          ]]></content>
          <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
          <tabTrigger>JSdes</tabTrigger> 
          <!-- Optional: Set a scope to limit where the snippet will trigger -->
          <scope>source.js</scope>
      </snippet>
    • 文件的后缀必须为 .sublime-snippet,只有这个后缀sublime text 才能识别代码块,才会有作用,把文件保存到目录: C:UsersqAppDataRoamingSublime Text 2PackagesUsersnippets   

      snippets是自己新建的文件夹,将所有的代码块文件放到这里,便于管理。

    • 使用代码块有两种方法,第一种是快捷的,写下触发tab键的代码块的名称,如下,然后点击tab键,奇迹就出现啦

    • 第二种当你点击ctr+shift+p:输入snippet:代码块的文件名称 就会显示你写的代码块,点击该文件就会出现代码块

    关于<scope>,官方定义如下: 其他文件类型的的代码块类似。

    ActionScript: source.actionscript.2
    AppleScript: source.applescript
    ASP: source.asp
    Batch FIle: source.dosbatch
    C#: source.cs
    C++: source.c++
    Clojure: source.clojure
    CoffeeScript: source.coffee
    CSS: source.css
    D: source.d
    Diff: source.diff
    Erlang: source.erlang
    Go: source.go
    GraphViz: source.dot
    Groovy: source.groovy
    Haskell: source.haskell
    HTML: text.html(.basic)
    JSP: text.html.jsp
    Java: source.java
    Java Properties: source.java-props
    Java Doc: text.html.javadoc
    JSON: source.json
    Javascript: source.js
    BibTex: source.bibtex
    Latex Log: text.log.latex
    Latex Memoir: text.tex.latex.memoir
    Latex: text.tex.latex
    LESS: source.css.less
    TeX: text.tex
    Lisp: source.lisp
    Lua: source.lua
    MakeFile: source.makefile
    Markdown: text.html.markdown
    Multi Markdown: text.html.markdown.multimarkdown
    Matlab: source.matlab
    Objective-C: source.objc
    Objective-C++: source.objc++
    OCaml campl4: source.camlp4.ocaml
    OCaml: source.ocaml
    OCamllex: source.ocamllex
    Perl: source.perl
    PHP: source.php
    Regular Expression(python): source.regexp.python
    Python: source.python
    R Console: source.r-console
    R: source.r
    Ruby on Rails: source.ruby.rails
    Ruby HAML: text.haml
    SQL(Ruby): source.sql.ruby
    Regular Expression: source.regexp
    RestructuredText: text.restructuredtext
    Ruby: source.ruby
    SASS: source.sass
    Scala: source.scala
    Shell Script: source.shell
    SQL: source.sql
    Stylus: source.stylus
    TCL: source.tcl
    HTML(TCL): text.html.tcl
    Plain text: text.plain
    Textile: text.html.textile
    XML: text.xml
    XSL: text.xml.xsl
    YAML: source.yaml
  • 相关阅读:
    redhat 新装后不能联网
    [Linux 命令]df -h
    redhat安装VMware tools的方法
    linux 进入包含空格文件名的文件夹
    Redhat 使用中文安装后更换为英文的设定
    HibernateDaoSupport类的使用
    java中重载与重写的区别
    Servlet中Service方法
    持久化框架Hibernate 开发实例(二)
    持久化框架Hibernate 开发实例(一)
  • 原文地址:https://www.cnblogs.com/qinbb/p/5804087.html
Copyright © 2011-2022 走看看