Sublime Text3高效開發之編寫代碼塊(snippet)
看到別人使用HBuilder X可以插入代碼塊,就想sublime text3有沒有類似的功能呢,誒還真有。在sublime text3叫作snippet。
-snippet是干什么的?:可以在你編寫js,html,vue,python...的時候快速插入自定義的代碼塊。
演示demo
輸入bt4carousel

輸入完bt4carousel按Tab

代碼生成完畢!
-snippet怎么使用?:新建sublime-snippet文件,編寫代碼塊,保存文件即可使用。
如何新建sublime-sinppet文件?

新建如下

Vue實例
<snippet>
<content><![CDATA[
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="${1:this}" alt="${2:this}">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="${3:this}" alt="${4:this}">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="${5:this}" alt="${6:this}">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
<tabTrigger>bt4carousel</tabTrigger>
<!-- <scope>text.html.basic</scope> -->
<scope>text.html.vue</scope>
</snippet>
Ctrl+S保存 推薦.......\Sublime Text 3\Packages\User下新建snippets文件夾
恭喜,自定義的snippet可以使用了,趕緊自己去試試吧。
如何查看特定文件的<scope>的值?:ctrl+alt+shift+p或者菜單欄-tools-developer-Show Scope Name,就能看到對應的值啦,點擊copy就可以復制值。
以上就sublime text3之snippet基本使用的所有內容,祝使用愉快,再見。

浙公網安備 33010602011771號