Home Download Buy Blog Forum Support

Hungry Backspace?

Hungry Backspace?

Postby mzehrer on Tue Dec 27, 2011 9:51 am

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
mzehrer
 
Posts: 3
Joined: Tue Dec 27, 2011 9:47 am

Re: Hungry Backspace?

Postby C0D312 on Tue Dec 27, 2011 9:43 pm

Sounds fairly simple for a plugin. I'll get back to you with one.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Hungry Backspace?

Postby jps on Wed Dec 28, 2011 1:15 am

Don't forget you can always press ctrl+backspace (option+delete on OSX) to achieve the same thing
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: Hungry Backspace?

Postby mzehrer on Wed Dec 28, 2011 2:20 pm

C0D312 wrote:Sounds fairly simple for a plugin. I'll get back to you with one.


Sounds great, maybe this will get me started writing my own plugins.
mzehrer
 
Posts: 3
Joined: Tue Dec 27, 2011 9:47 am

Re: Hungry Backspace?

Postby C0D312 on Wed Dec 28, 2011 6:08 pm

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: Select all
{ "keys": ["backspace"], "command": "delete_word", "args": { "forward": false, "sub_words": true }, "context":
  [
  { "key": "preceding_text", "operator": "regex_match", "operand": "^.*\\s", "match_all": true}
  ]
}


This should emulate a hungry backspace.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Hungry Backspace?

Postby mzehrer on Wed Dec 28, 2011 7:58 pm

C0D312 wrote: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: Select all
{ "keys": ["backspace"], "command": "delete_word", "args": { "forward": false, "sub_words": true }, "context":
  [
  { "key": "preceding_text", "operator": "regex_match", "operand": "^.*\\s", "match_all": true}
  ]
}


This should emulate a hungry backspace.


I use Linux, Ctrl+Backspace works on a single line but not over multiple lines.
mzehrer
 
Posts: 3
Joined: Tue Dec 27, 2011 9:47 am


Return to Technical Support

Who is online

Users browsing this forum: diesirae, Exabot [Bot], Google [Bot], rgidney and 20 guests