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



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



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



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



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



обновление



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



Полная версия, которая позволяет вы набираете через () но не проглотит символ закрытия, если вы ввели какой-либо текст:



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

]
}
605   3  

3 ответов:

добавьте это в файл привязки клавиш пользователя

{ "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, если предыдущий текст не заканчивается открывающей скобки. Второй перемещает курсор на одну позицию вперед, если он заканчивается открывающей скобкой. Если вы хоть немного знакомы с регулярными выражениями вы можете сделать то же самое для всех других видов скобки и кавычки.

изменить на ) привязка клавиш:

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

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

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

Я узнал при просмотре файла keybindings 'preferences / key bindings - default', что если вы выберете какой-либо текст и введите любой из них ({[. Он будет помещать скобки вокруг вашего текста.

Comments

    Ничего не найдено.