sublime text 的使用技巧

来源:互联网 发布:淘宝修真记小说 编辑:程序博客网 时间:2024/06/05 14:19

转载自知乎的回答

著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:Jasin Yip
链接:https://www.zhihu.com/question/24896283/answer/29380046
来源:知乎

使用 Sublime Text 建议掌握常用命令
1、查找打开过的文件:Ctrl+P,然后输入最近的文件名就可以即时预览到文件内容。
<img src="https://pic3.zhimg.com/9b7c4d67ea55e27ec8948fb2c62b52ce_b.jpg" data-rawwidth="1027" data-rawheight="577" class="origin_image zh-lightbox-thumb" width="1027" data-original="https://pic3.zhimg.com/9b7c4d67ea55e27ec8948fb2c62b52ce_r.jpg">2、命令输入框(不知道是不是这样叫):Ctrl+Shift+P2、命令输入框(不知道是不是这样叫):Ctrl+Shift+P
a)切换语法模式:
Set Syntax : [编程语言]
可以缩写为:
sspy
<img src="https://pic4.zhimg.com/cd557aaf5aa2070371c02f3c36d1b6d7_b.jpg" data-rawwidth="568" data-rawheight="165" class="origin_image zh-lightbox-thumb" width="568" data-original="https://pic4.zhimg.com/cd557aaf5aa2070371c02f3c36d1b6d7_r.jpg">这样就可以切换语法模式了,这以便于代码高亮及插件调用(比如HTML模式会使Emmet生效)这样就可以切换语法模式了,这以便于代码高亮及插件调用(比如HTML模式会使Emmet生效)
b)安装插件(前题是你安装了插件管理器):
<img src="https://pic2.zhimg.com/22ea96a4a0a384ea7489ad158af5cb4d_b.jpg" data-rawwidth="569" data-rawheight="76" class="origin_image zh-lightbox-thumb" width="569" data-original="https://pic2.zhimg.com/22ea96a4a0a384ea7489ad158af5cb4d_r.jpg">
输入这个命令之后回车,再输入需要的插件,就可以安装了。
<img src="https://pic1.zhimg.com/4d0c279219fa579b46cccca30604ae60_b.jpg" data-rawwidth="425" data-rawheight="421" class="origin_image zh-lightbox-thumb" width="425" data-original="https://pic1.zhimg.com/4d0c279219fa579b46cccca30604ae60_r.jpg">
3、多处编辑功能:
Ps:这个功能至关重要,我都不敢回想接触 Sublime Text 以前是怎么活过来的。
比如这样的代码:
<div>  <h2></h2>  <p></p>  <p></p></div><div>  <h2></h2>  <p></p>  <p></p></div><div>  <h2></h2>  <p></p>  <p></p></div>
如果我需要为所有 h2 换成 h1,再加上一个 class="title" 属性:
那么我只需要选中一个 h2,然后按住 Ctrl+D (因为按一下只会只选择下一个)
&amp;lt;img src=&quot;https://pic2.zhimg.com/126c6e1970e02bf5ae06abfff6a3eb59_b.jpg&quot; data-rawwidth=&quot;265&quot; data-rawheight=&quot;452&quot; class=&quot;content_image&quot; width=&quot;265&quot;&amp;gt;于是就变成:于是就变成:
&amp;lt;img src=&quot;https://pic2.zhimg.com/42145bea41de07290b7a2deafc64dc31_b.jpg&quot; data-rawwidth=&quot;286&quot; data-rawheight=&quot;428&quot; class=&quot;content_image&quot; width=&quot;286&quot;&amp;gt;然后我就可以输入 h1 ,就变成然后我就可以输入 h1 ,就变成
&amp;lt;img src=&quot;https://pic2.zhimg.com/2f144dfc0660469e055a961ff0275eed_b.jpg&quot; data-rawwidth=&quot;209&quot; data-rawheight=&quot;428&quot; class=&quot;content_image&quot; width=&quot;209&quot;&amp;gt;
这个时候,按一下 HOME (Mac下是Commond + 左箭头),再按几下右箭头,再输入
 class="title"
然后就变成
&amp;lt;img src=&quot;https://pic2.zhimg.com/7f10959c3299a98b99896ad7198ea001_b.jpg&quot; data-rawwidth=&quot;389&quot; data-rawheight=&quot;423&quot; class=&quot;content_image&quot; width=&quot;389&quot;&amp;gt;
欧了~!
这个可以举一反三,巨有用巨实用!




当然 Ctrl + F 调出查找功能、Ctrl + Shift + F 调出查找并替换功能应该不用讲了。


关于编码
&amp;lt;img src=&quot;https://pic3.zhimg.com/4441773188b44583f7bf8ea235a4dd4e_b.jpg&quot; data-rawwidth=&quot;570&quot; data-rawheight=&quot;426&quot; class=&quot;origin_image zh-lightbox-thumb&quot; width=&quot;570&quot; data-original=&quot;https://pic3.zhimg.com/4441773188b44583f7bf8ea235a4dd4e_r.jpg&quot;&amp;gt;
File -> Reopen with Encoding 可以以某编码打开
File -> Save with Encoding 可以保存为某一编码
编码问题就是这么简单~


关于中键,也就是鼠标滚轮
鼠标滚轮也可以选中字符,但不同用鼠标左键选择的是,他不会跨行选择,而是直接矩形选择,比如:
&amp;lt;img src=&quot;https://pic4.zhimg.com/cecaa7b4f9bdfab632020af1492ef51b_b.jpg&quot; data-rawwidth=&quot;161&quot; data-rawheight=&quot;202&quot; class=&quot;content_image&quot; width=&quot;161&quot;&amp;gt;配合 Ctrl 多处选择进行多处编辑,这直接是赞爆了有木有!!配合 Ctrl 多处选择进行多处编辑,这直接是赞爆了有木有!!



还有菜单里这个功能超赞!可以快速设置 Tab 的宽度,默认是4,也可以 Spaces 与 Tabs 之间转换。
(btw, 习惯用 Tab 缩进的程序猿,在提交代码时转换成2个空格的缩进是个好习惯)
&amp;lt;img src=&quot;https://pic2.zhimg.com/8c775c3efb3a2aef22d2cff88b993669_b.jpg&quot; data-rawwidth=&quot;599&quot; data-rawheight=&quot;610&quot; class=&quot;origin_image zh-lightbox-thumb&quot; width=&quot;599&quot; data-original=&quot;https://pic2.zhimg.com/8c775c3efb3a2aef22d2cff88b993669_r.jpg&quot;&amp;gt;


关于插件
插件太多了,Google/百度/知乎一搜就有推荐的,这里写推荐一个~!
写前端的话 Emmet 插件是必须的,比如:
输入
html:5
按TAB,会这样
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>Document</title></head><body></body></html>

输入
div
按TAB,会这样
<div></div>

输入
section#block$*3>h2.title+p.words*2
按TAB,会这样
<section id="block1">  <h2 class="title"></h2>  <p class="words"></p>  <p class="words"></p></section><section id="block2">  <h2 class="title"></h2>  <p class="words"></p>  <p class="words"></p></section><section id="block3">  <h2 class="title"></h2>  <p class="words"></p>  <p class="words"></p></section>

还有很多用法,可以自行Google/百度 “Emmet”。

0 0
原创粉丝点击