2016-07-28 33 views
3

在崇高的文本文件,我看到TM_CURRENT_WORD

$TM_CURRENT_WORD Current word under the cursor when the snippet was triggered. 

我很困惑,我將如何在實踐中使用下列定義。光標下的單詞不會總是tabTrigger中的單詞嗎?我試圖用這個參數傳入一個參數到Sublime代碼片段中,但無法讓它正常運行。

+3

你的困惑是基於這樣的想法,認爲只有這樣才能插入片段是通過標籤觸發器。但是,它們也可以通過鍵綁定或插件插入。 –

+0

謝謝你讓我知道。我發現這個鏈接,允許一個這樣做:http://stackoverflow.com/questions/15582210/sublime-text-how-to-make-shortcut-for-inserting-text – Abundance

回答

0

這個片段對我來說工作得很好:

<snippet> 
    <content><![CDATA[ 
Before you insert snippet cursor was in this "$TM_CURRENT_WORD" word.${0} 
]]></content> 
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> 
    <tabTrigger>word</tabTrigger> 
    <!-- Optional: Set a scope to limit where the snippet will trigger --> 
    <scope>text</scope> 
</snippet> 

there你可以找到非常有趣的例子:

<snippet> 
    <content><![CDATA[ = $TM_CURRENT_WORD + 1]]></content> 
    <tabTrigger>++</tabTrigger> 
    <description>i = i + 1</description> 
    <scope>source.fortran</scope> 
</snippet> 
+0

你知道,我已經看過那個鏈接看起來標籤觸發器是一種僥倖,因爲他不能用'--'做同樣的事情:「++爲你工作的事實更多的是運氣而不是設計,因爲由於某些原因,昇華看到++作爲一個單獨的「單詞」,但除了其他一些邊緣情況外,它幾乎不適用於其他任何內容。「 – Abundance

+1

@Andundance,你可以爲片段綁定快捷方式,而不是像你的問題評論中描述的那樣使用標籤觸發器 –