Sublime Forum

Hungry Backspace?

#1

How would I implement a function in Sublime Text 2 that modifies BackSpace key to hungrily delete whitespace? That means that one hit to the backspace key will automatically delete all whitespace chars backwards from the current cursor position up to the first non-whitespace character.

Best regards, Michael

0 Likes

#2

Sounds fairly simple for a plugin. I’ll get back to you with one.

0 Likes

#3

Don’t forget you can always press ctrl+backspace (option+delete on OSX) to achieve the same thing

0 Likes

#4

Sounds great, maybe this will get me started writing my own plugins.

0 Likes

#5

As @jps pointed out, this is possible using control+backspace. So I decided to just make this command into a keybinding.

Add the following to your “User Keybindings” (“Tools > Command Palette > User Keybindings” or “Preferences > Keybindings - User”)

[code]{ “keys”: “backspace”], “command”: “delete_word”, “args”: { “forward”: false, “sub_words”: true }, “context”:

{ “key”: “preceding_text”, “operator”: “regex_match”, “operand”: “^.*\s”, “match_all”: true}
]
}[/code]

This should emulate a hungry backspace.

0 Likes

#6

[quote=“C0D312”]As @jps pointed out, this is possible using control+backspace. So I decided to just make this command into a keybinding.

Add the following to your “User Keybindings” (“Tools > Command Palette > User Keybindings” or “Preferences > Keybindings - User”)

[code]{ “keys”: “backspace”], “command”: “delete_word”, “args”: { “forward”: false, “sub_words”: true }, “context”:

{ “key”: “preceding_text”, “operator”: “regex_match”, “operand”: “^.*\s”, “match_all”: true}
]
}[/code]

This should emulate a hungry backspace.[/quote]

I use Linux, Ctrl+Backspace works on a single line but not over multiple lines.

0 Likes

#7

I don’t think the above still works with recent version of Sublime Text. I got it working using the following:

{ "keys": ["backspace"], "command": "delete_word", "args": { "forward": false, "sub_words": true }, "context": [
    { "key": "preceding_text", "operator": "regex_match", "operand": "^\\s*", "match_all": true}
]}
0 Likes