代码编辑器Sublime Text的使用技巧,插件,快捷方式,代码块,缩写记录

来源:互联网 发布:aloha软件下载 编辑:程序博客网 时间:2024/05/17 02:54

Sublime Text 是一个代码编辑器,漂亮的用户界面和非凡的功能,例如迷你地图,多选择,Python的插件,代码段,等等。完全可自定义键绑定,菜单和工具栏。Sublime Text的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。

SublimeText2 支持但不限于 C, C++, C#, CSS, D, Erlang, HTML, Groovy, Haskell, HTML, Java, JavaScript, LaTeX, Lisp, Lua, Markdown, Matlab, OCaml, Perl, PHP, Python, R, Ruby, SQL, TCL, Textile and XML 等主流编程语言的语法高亮。


一:自定义代码块
在Tools—New Snippet...

出现


看着有点蒙逼对不对,没关系jack给你解析了它
<snippet>
   <content><![CDATA[ Hello, ${1:this} is a ${2:snippet}.]]></content>
   <![CDATA[ 你需要插入的代码片段]]>
   ${1:this}表示代码插入后,光标所停留的位置,可同时插入多个。其中:this为自定义参数
   ${2:snippet}表示代码插入后,按Tab键,光标会根据顺序跳转到相应位置(以此类推)。
   
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!— 翻译-可选:设置一个tabTrigger定义如何触发代码片段 -->
     打开注释,这个是我们要自定义的快捷键名称  比如note 回到代码note+tab即可显示
    <tabTrigger>hello</tabTrigger>

    <!-- Optional: Set a scope to limit where the snippet will trigger -->
   <!--翻译-可选:设定一个范围限制的代码片段将触发, -->
     不填写代表对所有文件有效。附:source.css和test.html分别对应不同文件。
     <scope>source.python</scope>
</snippet>

cmd+s保存在\Packages\User   文件名为(随便起名,最好和快捷键相同-code)mgnote-code,后缀名.sublime-snippet
保存即可

实例:
<snippet>
    <content><![CDATA[ <!--${1:note}--> ]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>mgnote</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

保存在\Packages\User  名为mgnote-code.sublime-snippet
回到工程输入mgnote+Tab即可 

二.安装Package Control 

Package Control 可以看做是一个ST2的扩展管理器,使用它,你可以用非常神奇、非常简单方便的方法去下载、安装、删除 Sublime Text 2 的各种插件、皮肤等,相信我,想更好地使用 ST2 绝对不能没有它!不过 ST2 本身并没有自带这个工具,我们需要自行安装它,方法很简单: 

法一

1、在 SublimeText2 的目录里面找到 Installed Packages 的文件夹 (如没有请手动新建) 

   finder--前往(按住alt)--资源库



2、下载 Package Control.sublime-package文件:http://download.csdn.net/detail/jackjia2015/9448581

3、将下载到的文件放进去 Installed Packages 里面 

4、重新启动 Sublime Text 即可如果 Package Control 已经安装成功,那么 Ctrl+Shift+P 调用命令面板,我们就会找到一些以“Package Control:”开头的命令,我们常用到的就是几个 Install Package (安装扩展)、List Packages (列出全部扩展)、Remove Package (移除扩展)、Upgrade Package (升级扩展)。


法二

但如果你按照上面的方法确实搞不定,可以试试按键盘 Ctrl+~ (数字1左边的按键)调出控制台,然后拷贝下面的代码进去并回车,它会自动帮你新建文件夹并下载文件的,与上面的方法最终效果是一样的:

import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp)ifnot os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())


三.插件推荐 

用Package Control安装插件的方法:
1.按下Ctrl+Shift+P调出命令面板
2.输入install 调出 Install Package 选项并回车

3.然后在列表中选中要安装的插件。

Clipboard History

功能:粘贴板历史记录

简介:方便使用复制/剪切的内容

使用:

  • Ctrl+alt+v:显示历史记录
  • Ctrl+alt+d:清空历史记录
  • Ctrl+shift+v:粘贴上一条记录(最旧)
  • Ctrl+shift+alt+v:粘贴下一条记录(最新)

keyboard

AutoFileName 

功能:快捷输入文件名

简介:自动完成文件名的输入,如图片选取

使用:输入”/”即可看到相对于本项目文件夹的其他文件

autofilename


SublimeCodeIntel

javascript 代码提示
点击弹出开发语言列表,选择对应开发语言,就会有相应代码补全。



推荐:http://www.xuanfengge.com/practical-collection-of-sublime-plug-in.html




四:显示右边栏

打开一个工程文件夹即可



如果不显示则在View—side Bar—show side Bar点击显示 





五:缩写

以下缩写打完按tab键显示
缩写:!
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

</body>
</html>


缩写:a
<a href=""></a>

缩写:a:link
<a href="http://"></a>

缩写:a:mail
<a href="mailto:"></a>

缩写:abbr
<abbr title=""></abbr>

缩写:acronym
<acronym title=""></acronym>


缩写:base
<base href="">

缩写:basefont
<basefont>

缩写:br
<br>

缩写:bdo
<bdo dir=""></bdo>

缩写:bdo:r
<bdo dir="rtl"></bdo>

缩写:bdo:l
<bdo dir="ltr"></bdo>

Link
缩写:link
<link rel="stylesheet" href="">

缩写:link:css
<link rel="stylesheet" href="style.css">

缩写:link:print
<link rel="stylesheet" href="print.css" media="print">

缩写:link:favicon
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">

缩写:link:touch
<link rel="apple-touch-icon" href="favicon.png">

缩写:link:rss
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml">

缩写:link:atom     
<link rel="alternate" type="application/atom+xml" title="Atom" href="atom.xml">

Meta
缩写:meta:utf
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

缩写:meta:win
<meta http-equiv="Content-Type" content="text/html;charset=windows-1251">

缩写:meta:vp
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

缩写:meta:compat
<meta http-equiv="X-UA-Compatible" content="IE=7">


缩写:style
<style></style>

缩写:script
<script></script>

缩写:script:src
<script src=""></script>



缩写:img
<img src="" alt="">

缩写:iframe
<iframe src="" frameborder="0"></iframe>

缩写:embed
<embed src="" type="">

缩写:object
<object data="" type=""></object>

缩写:param
<param name="" value="">

缩写:map
<map name=""></map>

area
缩写:area
<area shape="" coords="" href="" alt="">

缩写:area:d
<area shape="default" href="" alt="">

缩写:area:c
<area shape="circle" coords="" href="" alt="">

缩写:area:r
<area shape="rect" coords="" href="" alt="">

缩写:area:p
<area shape="poly" coords="" href="" alt="">

form
缩写:form
<form action=""></form>

缩写:form:get
<form action="" method="get"></form>

缩写:form:post
<form action="" method="post"></form>

缩写:label
<label for=""></label>

input
缩写:input
<input type="text">

缩写:inp
<input type="text" name="" id="">

缩写:input:hidden
别名:input[type=hidden name]
<input type="hidden" name="">

缩写:input:h
别名:input:hidden
<input type="hidden" name="">

缩写:input:text, input:t
别名:inp
<input type="text" name="" id="">

缩写:input:search
别名:inp[type=search]
<input type="search" name="" id="">

缩写:input:email
别名:inp[type=email]
<input type="email" name="" id="">

缩写:input:url
别名:inp[type=url]
<input type="url" name="" id="">

缩写:input:password
别名:inp[type=password]
<input type="password" name="" id="">

缩写:input:p
别名:input:password
<input type="password" name="" id="">

缩写:input:datetime
别名:inp[type=datetime]
<input type="datetime" name="" id="">

缩写:input:date
别名:inp[type=date]
<input type="date" name="" id="">

缩写:input:datetime-local
别名:inp[type=datetime-local]
<input type="datetime-local" name="" id="">

缩写:input:month
别名:inp[type=month]
<input type="month" name="" id="">

缩写:input:checkbox/input:c
别名:inp[type=checkbox]
<input type="checkbox" name="" id="">

缩写:input:radio
别名:inp[type=radio]
<input type="radio" name="" id="" />

缩写:input:r
别名:input:radio
<input type="radio" name="" id="">

缩写:input:range
别名:inp[type=range]
<input type="range" name="" id="">

缩写:input:submit/input:s
<input type="submit" value="">
缩写:input:image/input:i
<input type="image" src="" alt="">

缩写:input:button/input:b
<input type="button" value="">

缩写:isindex
<isindex>

缩写:input:reset
别名:input:button[type=reset]
<input type="reset" value="">

缩写:select
<select name="" id=""></select>

缩写:option
<option value=""></option>

缩写:textarea
<textarea name="" id="" cols="30" rows="10"></textarea>

缩写:menu:context
别名:menu[type=context]>
<menu type="context"></menu>

缩写:menu:c
别名:menu:context
<menu type="context"></menu>

缩写:menu:toolbar
别名:menu[type=toolbar]>
<menu type="toolbar"></menu>

缩写:menu:t
别名:menu:toolbar
<menu type="toolbar"></menu>

缩写:video
<video src=""></video>

缩写:html:xml
<html xmlns="http://www.w3.org/1999/xhtml"></html>

缩写:bq
别名:blockquote
<blockquote></blockquote>

缩写:acr
别名:acronym
<acronym title=""></acronym>

缩写:ifr
别名:iframe
<iframe src="" frameborder="0"></iframe>

缩写:emb
别名:embed
<embed src="" type="">

缩写:obj
别名:object
<object data="" type=""></object> 



1 0
原创粉丝点击