2013-04-15 58 views
4

我試圖自動關閉Markdown文件中的星號(*)字符。
我一直在尋找所有的語言設置文件,並沒有什麼可用的例子。我也嘗試編寫一個代碼片段,但發現它效率低下(它不包裹選擇)。崇高文本中的自定義括號自動關閉

我周圍搜索,發現BracketHighlighter(聲稱允許自定義自動關閉配對),但沒有運氣(通過包控制安裝,也重新啓動)。

任何想法,我應該從哪裏開始,或者我做錯了什麼?


解決方案(感謝@skuroda)

skuroda的回答會做得很好 - 不過,我已經作出了一些調整,我想追加到他們的答案:

{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "$0**"}, "context": 
    [ 
     { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, 
     { "key": "preceding_text", "operator": "regex_contains", "operand": "\\*\\*", "match_all": true }, 
     { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true } 

    ] 
} 

如果在兩個前面的星號旁邊按下星號鍵(例如**|,則***|變爲**|**,其中|是光標。這對文本的強化有很大的幫助。

回答

3

你可能需要調整一些上下文,但這應該是一個開始。這是基於內置括號中的自動配對鍵綁定。

{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*$0*"}, "context": 
    [ 
     { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, 
     { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true }, 
     { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true } 

    ] 
}, 
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*${0:$SELECTION}*"}, "context": 
    [ 
     { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }, 
     { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true } 
    ] 
}, 
{ "keys": ["*"], "command": "move", "args": {"by": "characters", "forward": true}, "context": 
    [ 
     { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, 
     { "key": "following_text", "operator": "regex_contains", "operand": "^\\*", "match_all": true }, 
     { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true } 
    ] 
} 
+0

有用的,但如果是該文件的位置,或者我會在哪裏保存此文件? –

+0

這些都基於默認的鍵綁定('首選項 - >鍵綁定 - 默認值)。您可以將這些條目放入您的用戶密鑰綁定文件('首選項 - >密鑰綁定 - 用戶')。哦,並作爲一個側面說明,我認爲支架熒光筆只是讓你定義括號突出不配對,雖然我可能是錯的。 – skuroda

+0

謝謝,這很好。我已經調整了一些代碼,以便可以輕鬆訪問插件。 –

1

使用此

{ "keys": ["*"], "command": "insert_snippet", "args": {"name": "Packages/User/my-snippet.sublime-snippet" }} 

現在去首選項>瀏覽包,然後用戶文件夾 創建一個文件

我-snippet.sublime - 摘錄

並在

內使用以下代碼
<snippet><content><![CDATA[ 
*${0:$SELECTION}* 
]]></content></snippet> 

好運