LoginSignup
1
0

More than 5 years have passed since last update.

SublimeText3 - バッククオートを自動ペア入力するコンフィグ

Last updated at Posted at 2016-06-03

SublimeText3 コンフィグメモ

概要

markdown でよく使う`(バッククオート)を入力した時に"'を入力した時にやってくれるような自動ペアリング処理をさせたい。

経緯的な何か

そもそも以前の ST3 では"'(),{}など、デフォルトではいい感じに動いていなかったが現在の SublimeText3(build 3114)では

のあたりの議論がいつの間にか公式に取り込まれた模様。

つまり、ペアにする文字を追加で設定するするのではなくキーバインディングで`が入力されたときの動作設定をごそっと追加する方式。

参考にする設定

なので現在の ST3 ではデフォルトのキーバインディング設定が参考になる。

メニュー > Preferences > Key Bindings > Default

を開いて// Auto-pair single quotesとコメントされている辺りのコンフィグを見つける。

他にも// Auto-pair xxxxx quotesとか// Auto-pair xxxx bracketsという感じで設定されているので自分で見やすい奴をピックアップ。

見つけたコンフィグのクオート文字を`に変更したものを User のキーバインド設定に追加すれば良い。

コンフィグする

Preferences > Key Bindings > User に設定を追加する

メニューから以下を開いて設定を追加する

Preferences > Key Bindings > User

Default に書き込むとST3のアップデートとかで書き換わる可能性がある(っていうか多分書き換えられたのでこのメモを作ることになった)ので User のキーバインドに設定する。

実物はこんな感じ。

[
    // Auto-pair back quotes
    { "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.single - punctuation.definition.string.end", "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 },
            { "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
            { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "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": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
            { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true },
        ]
    },
]
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0