[Ubuntu] Tạo snippets cho sublime text
Vào Tools/ New snippet…
Tại file mở ra bạn sẽ thấy:
<snippet>
<content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></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> -->
</snippet>
Lưu lại với tên filename.sublime-snippet
Bạn chú ý Hello, ${1:this} is a ${2:snippet} chính là đoạn code đầy đủ mà bạn ấn tab.
Thay <!– hello –> bằng hello với hello là từ khóa tắt. sau khi bạn viết hello và ấn tab thì sẽ hiện ra Hello, this is a snippet
Các giá trị trong $ gồm ${1:this} is a ${2:snippet} là các giá trị khi ấn tab thì sẽ nhảy đến và bạn có thể thay thế chúng bằng giá trị của mình.
VD tạo 1 file while.sublime-snippet. Khi ấn while và tab thì sẽ hiện ra:
while (${1:/* condition */})
{
${2:/*code*/}
}
Với các giá trị /* condition */ và /*code*/ có thể nhanh chóng thay thế .
<snippet>
<content><![CDATA[
while (${1:/* condition */})
{
${2:/*code*/}
}
]]></content>
<tabTrigger>while</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>



Phản hồi gần đây