1

說我的代碼是這樣的:如何在崇高文本中編寫「動態」片段?

datatype type_name = 
    | a of() 
    | b of() 
    ... // more 

是否有可能對我產生我每次按Tab鍵| ${place_holder} of()對?

我現在的片段是:

<snippet> 
    <content><![CDATA[ 
datatype ${1:type_name} = 
    | ${2} of (${3}) 
    ${4} 
]]></content> 
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> 
    <tabTrigger>dat</tabTrigger> 
    <!-- Optional: Set a scope to limit where the snippet will trigger --> 
    <scope>source.ats</scope> 
</snippet> 

但正如你看到的,那麼用戶命中的選項卡中的第四次,我無法生成另一個| of()對。

+0

爲什麼不分配'| ($ {2})的$ {1}'到鍵盤快捷鍵? – MattDMo

回答

0

下面是使用替換的(不雅)黑客攻擊。當選擇第四個字段時,按照您希望的次數按空格鍵。

<snippet> 
    <content><![CDATA[ 
datatype ${1:type_name} = 
    | ${2} of (${3}) 
    ${4:(spacebar)} 
    ${4/ /| a of()\n\t/g} 
]]></content> 
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> 
    <tabTrigger>dat</tabTrigger> 
    <!-- Optional: Set a scope to limit where the snippet will trigger --> 
    <scope>source.python</scope> 
</snippet> 

更好的解決方案可經由$ PARAM環境變量是可能的:你可能能夠傳遞給insertSnippet的整數,用它來構造通過上面所示的替代實施例的替換文本。文檔是here,但不幸的是在$ PARAM上沒有提供任何信息。 This post也爲如何傳遞參數提供了一個有用的示例。