zoukankan      html  css  js  c++  java
  • Sublime Text 2创建可复用的代码片段

    对于前端工程师来讲,写一个html页面的基本结构是体力活,每次去拷贝一个也麻烦,sublime text 2 提供了一个很好的复用代码片段。下面介绍一下创建一个html5的代码片段的过程。
    在菜单上点击Tools -> New Snippet,会新建一个xml文件页签:

    1 <snippet>
    2     <content><![CDATA[
    3 Hello, ${1:this} is a ${2:snippet}.
    4 ]]></content>
    5     <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    6     <!-- <tabTrigger>hello</tabTrigger> -->
    7     <!-- Optional: Set a scope to limit where the snippet will trigger -->
    8     <!-- <scope>source.python</scope> -->
    9 </snippet>

    注释已经说的比较详细了。
    content 里面就是代码模版:${序号:默认值} ,序号相同的地方光标会同时停在那可以多处同时编辑。序号大小就是tabindex。在实际使用代码的时候,可以使用tab切换光标位置。
    tabTrigger是指输入该字符串后tab就是在光标插入content中的内容。
    scope是指在何种文件类型中使用。
    下面是html5代码片段的定义:

     1 <snippet>
     2     <content><![CDATA[
     3 <!doctype html> 
     4 <html lang="en"> 
     5 <head> 
     6     <meta charset="UTF-8"> 
     7     <title>${1}</title> 
     8 </head>
     9 <body>
    10     <h1>${1}</h1>
    11     Hello, ${2:this} is a ${3:snippet}.
    12 </body>
    13 </html>
    14 ]]></content>
    15     <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    16     <tabTrigger>html5</tabTrigger>
    17     <!-- Optional: Set a scope to limit where the snippet will trigger -->
    18     <!-- <scope>source.python</scope> -->
    19 </snippet>

    编辑完之后保存为 C:Users[用户]AppDataRoamingSublime Text 2PackagesUserhtml5.sublime-snippet  (Win7下) 默认的保存路径就行。后缀必须是.sublime-snippet。
    保存完重启Sublime text 2,新建文件:输入html5,tab会出现如下效果:

    ${1}出现了两次,所以光标同时编辑图中两处。
    ${2:this},所以在2处出现this默认值。${1}处编辑完按tab就到${2}处。
    OK, That's all。

  • 相关阅读:
    解决PyQt5在安装后无法找到Designer.exe问题,两个位置可供参考
    观察者模式
    策略模式
    模板方法模式(下)
    学过的技术容易忘,怎么办?
    Mysql主从配置
    Springboot处理CORS跨域请求
    SpringBoot学习2之注解简单配置Springboot+MyBatis
    Confluence7.4安装并破解汉化教程
    mysql json类型
  • 原文地址:https://www.cnblogs.com/liubeimeng/p/3861007.html
Copyright © 2011-2022 走看看