Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

When I type command-backspace in a Cocoa text field, it deletes everything from the start of the current line to the cursor point. Can this be disabled? It's driving me nuts because I hit it all the time by accident.

I've tried adding the following to ~/Library/KeyBindings/DefaultKeyBinding.dict:

<key>@\010</key><!-- cmd-backspace -->
<string>deleteWordBackward:</string>

or:

<key>@\177</key><!-- cmd-delete -->
<string>deleteWordBackward:</string>

or:

<key>@\U007F</key><!-- cmd-backspace -->
<string>deleteWordBackward:</string>

... all to no apparent effect. I can't tell if I'm getting the keycode for backspace / delete wrong, or if I'm wrong that @ is the command key, or if something else is wrong.

Finally - and I hesitate to mention this because of the source, but it's just the only clue that I have - some random commentor on this TextMate-related blog post says:

unfortunately most of the key combinations which include the command modifier never reach the control which have focus (they're eaten by the menu manager code).

So these bindings generally do not work :(

I go through hoops to get as many keys as I currently do in TextMate, and here I still can't get command backward delete (⌘⌫).

Is there something else I can try?

edit: realize I had pasted the wrong info in as the configs that I've tried. If you notice changes up there, I'm changing the question to match what I actually did. The behavior didn't change :).

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

Make the contents of your ~/Library/KeyBindings/DefaultKeyBinding.dict look like the text below

/* my keybindings */

{
"@\U007F" = "deleteWordBackward:"; /* delete backwards one word */
}  
  • '@' represents the command key
  • '\U007F' represents the delete key
  • 'deleteWordBackward' is a keyword which Cocoa applications understand

Once you restart any Cocoa app, this will now just delete one word to the left of the cursor instead of everything between the beginning of the line and the cursor.

share|improve this answer
1  
That seemed to work, thanks. Any idea why that didn't work in plist format? (Am I going to regret migrating the rest of my DefaultKeyBinding.dict away from plist format?) –  Micah R Ledbetter Sep 14 '11 at 20:33
1  
I don't know why it didn't work in the XML format, could you amend your question to include the full contents of your file and maybe I could help? Or better yet, ask a new question which shows both versions in full and I or somebody else might be able to tell you. –  conorgriffin Sep 14 '11 at 20:41
1  
+1 for the awesome answer - better to ask a new question and leave this simple and correct as asked... –  bmike Sep 14 '11 at 20:44
1  
OK, I asked a new question as suggested over here. Thanks for your help, guys. –  Micah R Ledbetter Sep 14 '11 at 21:41
    
I love helping people that have such well researched questions - these two are great! –  bmike Sep 15 '11 at 0:44
add comment

\U007f and \177 are specific to old-style property lists. On XML plists you'd need to use &#x007f; or a literal DEL:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>@&#x007f;</key>
    <string>noop:</string>
</dict>
</plist>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.