7

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 :).

2 Answers 2

5

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.

7
  • 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?) Sep 14, 2011 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. Sep 14, 2011 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, 2011 at 20:44
  • 1
    OK, I asked a new question as suggested over here. Thanks for your help, guys. Sep 14, 2011 at 21:41
  • I love helping people that have such well researched questions - these two are great!
    – bmike
    Sep 15, 2011 at 0:44
2

\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>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .