63

Sublime にはこの動作があり、多くの括弧を使用して構造を入力する必要がある場合に、非常に煩わしいことがあります。入力すると、カーソルが(追加されて中央に配置されますが、入力すると、閉じ括弧が静かに飲み込まれます。())

長い正規表現を入力すると、ブラケットのバランスがすぐに崩れてしまい、気が狂ってしまうので、これは本当に面倒です。したがって、次のような構造になり(([a-z])ます。

問題は、これを無効にする方法はありますか? 閉じ括弧を入力した場合、飲み込まれないように保持します。

Sublime configs を調べてググってみましたが、誰もこの振る舞いを気にしていないようです。私はそれを間違って使用していますか?

アップデート

Sublime: Jump out of matching bracketsショートカットも確認​​することをお勧めします。

()で入力できますが、テキストを入力した場合に終了記号を飲み込まないフルバージョン:

  { "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "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": "preceding_text", "operator": "regex_contains", "operand": "[^\"]$", "match_all": true }
      ]
  },
  { "keys": [")"], "command": "insert", "args": {"characters": ")"}, "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": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "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": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
      ]
  },
  { "keys": ["'"], "command": "insert", "args": {"characters": "'"}, "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": "preceding_text", "operator": "regex_contains", "operand": "'$", "match_all": true }
      ]
  },
  { "keys": ["]"],"command": "insert", "args": {"characters": "]"}, "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": "preceding_text", "operator": "regex_contains", "operand": "[$", "match_all": true }
      ]
  },
  { "keys": ["}"], "command": "insert", "args": {"characters": "}"}, "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": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true }

      ]
  }
4

3 に答える 3

50

これをユーザーキーバインドファイルに追加します

{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "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 }
    ]
}

閉じ括弧を挿入する代わりに、カーソルを1つ前に移動する1つのキーバインドをオーバーライドします。したがって、本質的には、あなたが望むことを正確に行う必要があります。

この動作を完全に無効にしたい場合は、すべての種類の括弧と引用符について、完全なユーザー キーバインドの部分を次に示します。

{ "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "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": [")"], "command": "insert", "args": {"characters": ")"}, "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": ["'"], "command": "insert", "args": {"characters": "'"}, "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": ["]"],"command": "insert", "args": {"characters": "]"}, "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": ["}"], "command": "insert", "args": {"characters": "}"}, "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 }
    ]
}

編集:

カーソルが開き括弧の直後にある場合は閉じ括弧をスキップし、それ以外の場合はそれを出力したい場合は、キーバインドを分割してこれら 2 つの可能性を区別できます。

{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "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": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "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": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
    ]
},

前のテキストが開き括弧で終わっていない場合、最初のものは文字を挿入します。2 番目のものは、カーソルが開き括弧で終わっている場合、カーソルを 1 位置前に移動します。正規表現に少し慣れている場合は、他のすべての種類の括弧と引用符についても同じことができます。

于 2013-04-28T23:09:28.400 に答える
8

)キー バインドを再定義します。

{ "keys": [")"], "command": "insert", "args": {"characters": ")"} }

編集: もう 1 つの方法は、auto_match_enabled設定を有効/無効にすることです (したがって、自動ペアリングの動作を変更します)。キーボード ショートカットを使用して自由に切り替えることができます。

{ "keys": ["alt+m"], "command": "toggle_setting", "args": {"setting": "auto_match_enabled"} }
于 2012-12-26T13:56:41.003 に答える
-2

キーバインディングファイルの「設定/キーバインディング-デフォルト」を参照すると、テキストを選択してこれらのいずれかを入力すると({[。テキストの周りに角かっこが配置されます。

于 2013-03-05T21:34:21.883 に答える