Sublime Forum

Angle bracket deletes selected word instead of to embed it <Foo>. How to enable?

#1

I want the same behavior for angle brackets < > as we have for these brackets { [ " ' (.
When I select a word and hit a button with those brackets the result is an embedded word:

[Foo] or {Foo} or "Foo" etc..

However it is not the case for angle brackets. An angle bracket deletes selected word. How to enable it?

0 Likes

#2

Just add this to your keymap:

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

If you realy want the “same” behavior you can also add these keybindings (to add <> when pressing <) you can add this keybinding, but I don’t recommend that:

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

#3

Hi!

And add this to your settings user:

"auto_close_tags": false

(prevent default behaviour)

Matt

0 Likes