Sublime Key Binding "TAB" to exit parenthesis, quotes etc, EXCEPT when it is the first character on the line

122 Views Asked by At

I'm trying to get "TAB" to exit parenthesis, quotes, etc. but only when it is NOT the only character on the line. If | represents the cursor:

Exit here:

function(e|) {}

But not here:

function() {
  return;
|}

To do so I'm trying to set the context to check for that condition without any success. Here is what I have so far:

{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
    { "key": "following_text", "operator": "regex_contains", "operand": "^[)'}\"\\]]", "match_all": true },
    { "key": "preceding_text", "operator": "not_regex_match", "operand": "\\n", "match_all":true },
    { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
}

The second line of the context is what I can't get right. Any help would be greatly appreciated!

Best,

Michael

1

There are 1 best solutions below

0
r-stein On BEST ANSWER

Since you want to match until the line start you should use ^. The regex match is only per line, hence you can use ^ for the begin and $ for the end of the line. Change it to ^\\s* if you also want to disable it for lines with indent, e.g. to press the tab multiple times to indent the bracket.