Just go to shortcut key preferences: Preferences → Key Bindings.
In preferences default (editor on the left) you will see that there are already options for "Self-epair" for quotes, parentheses, etc. Then just copy one of them to your preferences (editor on the right side), changing the character indicated for the dot. Stay like this:
{ "keys": ["."], "command": "insert_snippet", "args": {"contents": ".$0."}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": false},
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[.a-zA-Z0-9_]$", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true }
]
},
{ "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": false }
]
},
{ "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": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "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 },
{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single - punctuation.definition.string.end", "match_all": true },
]
},
Basically, I copied one of the existing settings (picked from the quotes) and changed the quotes to point: in "keys": ["."]
, "contents": ".$0."
, and other places. One detail is that at some points there are regular expressions, and so I needed to escape the point with \
(since the point has special meaning in regex and it is necessary to make the escape). But since the value is inside a string, I needed to write the \
as \\
(as in "operand": "^\\."
, for example).
With this, it is now possible to place the dot around the selected text:
I also changed some values of true
for false
(in the first 2 configurations of keys
):
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": false}
If you leave "operand" and "match_all" as true
, when typing a single point (with no text selected), he puts another point right after (as with the quotation marks or parentheses, which he automatically puts the closure). Switching to false
, I avoid this behavior.