it-swarm-ja.com

SublimeTextの「ラップ」文字をカスタマイズする

Sublime Textで、テキストを強調表示し、次の記号のいずれかを押します。

'
"
(
{
[

ハイライトされたセクション全体が、押したキー(またはそれに対応する記号)で囲まれます。このリストにさらに文字を追加するオプションはありますか? Ruby開発では、|と `をかなり頻繁に使用します。

5
Devon Parsons

たまたま、バックティック( `)のキーバインドを既に設定しているので、パイプ|のキーバインドを簡単に変更できるはずです。これを行うには、Preferences -> Key Bindings-Userを開きます。ファイルが空の場合は、開き角かっこと[]を別々の行に追加し、それらの間に以下を貼り付けます。

// Auto-pair backticks
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$|;)", "match_all": true },
        { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[`a-zA-Z0-9_]$", "match_all": true },
        { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true }
    ]
},
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
    ]
},
{ "keys": ["`"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
    ]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
    ]
},

パイプ文字の場合、|には特別な意味があるため、一部の正規表現を少し変更する必要があります。以下は私のために働きます:

// Auto-pair pipes in Ruby
{ "keys": ["|"], "command": "insert_snippet", "args": {"contents": "|$0|"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$|;)", "match_all": true },
        { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\\|a-zA-Z0-9_]$", "match_all": true },
        { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "source.Ruby", "match_all": true }
    ]
},
{ "keys": ["|"], "command": "insert_snippet", "args": {"contents": "|${0:$SELECTION}|"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "source.Ruby", "match_all": true }
    ]
},
{ "keys": ["|"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "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": "source.Ruby", "match_all": true }
    ]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\|$", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\|", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "source.Ruby", "match_all": true }
    ]
}

セレクターsource.Ruby|キーバインディングに追加したことに気付くでしょう-Ruby code以外の他のファイルで使用したい場合は、これを削除または変更できます。他の構文で使用できるため、バッククォートコードには追加しませんでした-PythonそしてMarkdownが最初に頭に浮かぶものです。

7
MattDMo