Save This @:
/Packages/___Your_Macro_Folder___/Delete Surrounding Spaces.sublime-macro
[
{ "command": "left_delete" },
{ "command": "right_delete" },
]
Add This @:
Preferences > Key Bindings - User
// delete surrounding spaces if they exist
{
"keys": [ "shift+backspace" ],
"command": "run_macro_file",
"args": { "file": "res://Packages/___Your_Macro_Folder___/Delete Surrounding Spaces.sublime-macro" },
"context": [
{ "key": "preceding_text", "operator": "regex_match", "operand": ".*\\S " },
{ "key": "following_text", "operator": "regex_match", "operand": " \\S.*" },
] },
// otherwise do nothing
// ( this is optional. I personally sometimes hold shift while I'm typing & deleting,
// so I prefer `shift+backspace` to function the same as `backspace`. )
{
"keys": [ "shift+backspace" ],
"command": "_____NULL_____",
"context": [ { "key": "preceding_text", "operator": "not_regex_match", "operand": ".*\\S ", "match_all": true } ]
},
{
"keys": [ "shift+backspace" ],
"command": "_____NULL_____",
"context": [ { "key": "following_text", "operator": "not_regex_match", "operand": " \\S.*", "match_all": true } ]
},
Edit:
I originally recommended a Chain Of Command implementation, but just realized that it uses multiple edit objects - which doesn’t allow you to undo the entire chain with a single undo
command.