Подтвердить что ты не робот

Как предотвратить Sublime Text 2 от проглатывания закрывающих скобок, котировок и круглых скобок?

Sublime имеет такое поведение, которое действительно раздражает, когда вам приходится вводить конструкции с большим количеством скобок. Когда вы набираете (, он добавляет () и помещает курсор в середину, все отлично, если вы, однако, наберете ), он беззвучно проглотит закрывающую скобку.

Это очень раздражает при наборе длинных регулярных выражений, потому что скобки становятся неуравновешенными довольно быстро, и это сводит меня с ума. Таким образом, вы получаете такие конструкции, как (([a-z]).

Итак, вопрос в том, есть ли способ отключить это? Если я напечатаю закрывающий кронштейн, я хочу, чтобы он остался, не проглатывался.

Я проверил через Sublime configs, googled, но никто, кажется, не возражает против этого поведения. Я использую это неправильно?

Обновление

Возможно, вы захотите проверить 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 }

      ]
  }
4b9b3361

Ответ 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 }
    ]
},
{ "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 }
    ]
}

EDIT:

Если вы хотите пропустить закрывающий кронштейн, если курсор находится прямо после открывающей скобки и распечатать его во всех других случаях, вы можете разделить свои комбинации клавиш, чтобы различать эти две возможности:

{ "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 }
    ]
},

Первый вставляет charcater, если предыдущий текст не заканчивается открывающей скобкой. Второй перемещает курсор на одну позицию вперед, если он заканчивается с помощью открывающей скобки. Если вы немного знакомы с регулярными выражениями, вы можете сделать то же самое для всех других скобок и цитат.

Ответ 2

Переопределите привязку ):

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

Изменить. Еще один способ - включить/отключить параметр auto_match_enabled (таким образом, изменив поведение автоматического спаривания), вы можете переключать его по желанию с помощью сочетания клавиш:

{ "keys": ["alt+m"], "command": "toggle_setting", "args": {"setting": "auto_match_enabled"} }

Ответ 3

Я обнаружил, что при просмотре файла привязки клавиш "предпочтения/привязки клавиш - по умолчанию", если вы выберете какой-либо текст и введите любой из них ({[.], он поместит скобки вокруг вашего текста.