Sublime Forum

Auto spacing and quoting inside square brackets

#1

I am using the following snippet in the key binding file to automatically close a square bracket and put a leading and trailing spance.

// Auto-pair square brackets
{ "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 }
    ]
},

So, when I type [ it gets converted to [ | ]. Now what I want to do is, after this, when I type ' or ", the leading and trailing spaces get deleted.

Type: [
Result: [ | ]
Type: [ ' ]
Result: ['|']

Can anyone help me with this?

0 Likes

#2

This is similar to Customizing key bindings, except you would run left_delete and right_delete once each and then insert the '$0' snippet.

0 Likes

#3

Thank you. Macro is what I need.

0 Likes