Key bindings for switchers

This entry isn't just for switchers, but I've gotten several requests for making the home/end function keys go to the beginning/end of current line, which is how Windows does it, hence the title.

While this is possible to setup within TextMate, I'm certain that the people requesting this would be happier with a solution that applies to all good OS X citizens (i.e. who make use of the standard key bindings system like Mail, Safari and other Cocoa applications). So here's a detailed description of how to achieve this and more.

The standard key bindings are located in this file: /System/​Library/​Frameworks/​AppKit.framework/​Resources/​StandardKeyBinding.dict. This file is in XML, and function keys are stored using their actual character code, making it a bit hard to decipher, for our customization we'll use the old-style ASCII format, and we'll ignore this base file (since the system merges the files, giving our local file precedence when there's a conflict).

Our local file should be located in ~/Library/KeyBindings, this folder may not exist, so to create it (from Terminal) execute:

mkdir ~/Library/KeyBindings

Next we'll create the actual key bindings file, which for some reason is named DefaultKeyBinding.dict. To create the file (if it doesn't already exist), again from Terminal execute:

cd ~/Library/KeyBindings
touch DefaultKeyBinding.dict
open -a TextMate DefaultKeyBinding.dict

This should open a (probably blank) file in TextMate (if you want to use another text editor, you're on your own!). The format of the key bindings file is this:

{
    «key» = «action»;
    …
}

The key is a string representation of the key you want to bind, and action is one of the many Cocoa action methods defined in the NSResponder class (scroll down and you'll see them, most are self explanatory by name).

The string representation of a key is more tricky. For normal characters (like letters, digits, punctuation etc.), the string representation is the actual character. If you want to include a modifier in the binding, you can prepend one or more of the following characters to the string representation:

CharacterRepresents
$⇧ (shift)
^⌃ (control)
~⌥ (option)
@⌘ (command)
#number pad

Shift is only used with function keys. E.g. if you want to bind something to shift-A, you'll use A (as opposed to $a), and if you want to bind to shift-1, you'll use ! (which makes the binding keymap sensitive).

Function keys are for the most part defined (as character codes) in NSEvent.h. In the string representation these would be written as \Unnnn. Here's a table of the most interesting keys:

Character codeDescription
\UF700arrow up
\UF701arrow down
\UF702arrow left
\UF703arrow right
\UF728forward delete
\U007Fbackward delete
\UF729home
\UF72Bend
\UF72Cpage up
\UF72Dpage down
\U001Bescape
\U0009tab
\U0019backtab (shift tab)
\U000Dreturn
\U0003enter

Given the above information we can now rebind home/end to move to the beginning/end of line, and page up/down to actually move the caret. This would look like the following:

{
    /* home */
    "\UF729"  = "moveToBeginningOfLine:";
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:";

    /* end */
    "\UF72B"  = "moveToEndOfLine:";
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";

    /* page up/down */
    "\UF72C"  = "pageUp:";
    "\UF72D"  = "pageDown:";
}

Now save the file and restart your Cocoa applications for the changes to take effect.

72 Comments

  1. 05 Jul 2005 | # Simon Stapleton wrote…

    That's lovely.

    I'd forgotten how much I love OSX (well, hadn't thought about it over the last 5 minutes, at least)

    Simon

  2. 08 Jul 2005 | # B wrote…

    As a long-time Windows and Mac OS user, I think most people would appreciate not having to edit the file by hand, but rather have a preference item for this and a few other similar features. This is pretty basic stuff when it comes to configuration (too bad most other apps, and the OS for the most part, has it wrong).

    B.

  3. 09 Jul 2005 | # Mk wrote…

    Edited: See next comment

  4. 09 Jul 2005 | # Mk wrote…

    Grrr... Should have known the HTML in my example would get stripped. Here's a second try.

    As a longtime and loyal BBEdit user, I’m currently exploring TextMate, and I’ve got to say I’m impressed. There are a small handful of BBEdit features that I’d like to see come to TM, before I’m ready to become that kind of switcher. One of the small ones is that I really like that I can Option-Right/Left to move the carat to the beginning/end of the next/previous HTML tag on the line in BBEdit.

    Example (numbers show where each consecutive Option-Right keypresses will place the carat):

    BBEdit <span>(1)Test(2)</span>(3)

    TextMate <span(1)>Test(2)</(3)span(4)>(5)

    For me, as a keyboard navigator, that increase in keystrokes gets to be a little tiresome. Is it possible to configure TextMate (that is, OS X) to Option-Arrow the BBEdit way using the technique above?

    It looks like TM is well on its way to becoming one of the great editors for the Mac. Nice work.

  5. 09 Jul 2005 | # Andreas Wahlin wrote…

    I can't get this to work, I don't know if I have anything wrong … here's a little terminal output that might help to determine if anything's wrong …

    c-bc8a70d5:~/Library/KeyBindings perihelion$ ls -a . .DS_Store .. DefaultKeyBinding.dict

    but it all seems to be in the correct place, no? I changed the file, and then I restarted, btw, my file looks like

    { "\UF729" = "moveToBeginningOfLine:"; /* Home / "\UF72B" = "moveToEndOfLine:"; / End / "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; / Shift-Home / "$\UF72B" = "moveToEndOfLineAndModifySelection:"; / Shift-End / "@\UF729" = "moveToBeginningOfDocument:"; / Command-Home / "@\UF72B" = "moveToEndOfDocument:"; / Command-End / "$@\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; / Shift-Command-Home / "$@\UF72B" = "moveToEndOfDocumentAndModifySelection:"; / Shift-Command-End / "\UF72C" = "pageUp:"; / page up / "\UF72D" = "pageDown:"; / page down / "\U0009" = "indent:"; / non-destructive indent */ }

    the last thing there was a try,because I really want to in/out-dent entire selected blocks with tab and shift tab.

  6. 09 Jul 2005 | # Matt Pelletier wrote…

    Awesome. I added a few more that handle Ctrl-Left and Ctrl-Right for word movement (moveWordLeft/moveWordRight), and Ctrl-Shift-Left and Ctrl-Shift-Right for word movement with selections (moveWordLeftAndModifySelection etc.). From what I have been told this already works when using a mac keyboard plugged directly into the mac, but I am working through VNC (it's actually better than using windows editors to code!) and these key-bindings aren't working properly by default. So I added the following and it works just the way I like.

    Thanks.

    Matt

  7. 10 Jul 2005 | # Allan Odgaard wrote…

    Mk: to get this behavior in TextMate what you'd do is something like Start Macro Recording, do a regular expression find, to locate where you'd want the caret to go, then Stop Macro Recording, save the macro with key equivalent set to option-right arrow. Maybe also set the scope of this new macro to “text.html”, so it's only for HTML text you'd get this behavior.

    Currently though, regular expression finds are only supported for forward searches, so it'd be more tricky to get similar behavior for option-arrow left. I do intend to add this in a few betas — tell you what, when I do (add backwards regex find), I'll add these macros to the default HTML bundle, so it'll work like you request out-of-the-box.

    Andreas: I don't know why it doesn't work for you. Try to run: pl < DefaultKeyBinding.dict, this will tell you if the file is valid (you can also load it into TextMate and press ctrl-shift-V for the same).

    TextMate btw has shift left/right on option-tab and option-shift-tab.

    Restarting the application should be enough for the changes to take effect.

  8. 11 Jul 2005 | # B wrote…

    I use Windows remote desktop so I can continue to use Textpad. It's worth buying a PC and installing remote desktop to use. There's nothing on the Mac (not even Textmate yet) that comes anywhere close.

    BBEdit and TextWrangler are a complete joke.

  9. 19 Jul 2005 | # pjm wrote…

    You're kidding right? (re Textpad). The screenshot on the Textpad page is almost comical… I know there's got to be some text on there somewhere, but it's all squeezed in by the hideous surrounds. Like Eclipse, only a teensy weensy little bit uglier; something I thought I'd never be able to write.

    Give me TextMate's cleanliness and lack of bloat any day of the week.

    [[You wouldn't happen to develop Textpad by any coincidence???]]

  10. 09 Aug 2005 | # kenrick wrote…

    this post made me purchase textmate today. i didnt want to buy it before because i am a switcher and i use the home/end keys alot. thanks!

  11. 10 Sep 2005 | # Mikkel Rasmussen wrote…

    Hey

    Great post, but it doesn't work :-( (for me, at least, on Tiger 10.4.2)

    I created the KeyBindings dir and the file, copied the code from this post, saved and restarted. I did not add any more lines. The result of the proposed test is:

    Mira:/Library/KeyBindings mikkelbo$ pl < DefaultKeyBinding.dict { "$Uf729" = "moveToBeginningOfLineAndModifySelection:"; "$Uf72b" = "moveToEndOfLineAndModifySelection:"; "Uf729" = "moveToBeginningOfLine:"; "Uf72b" = "moveToEndOfLine:"; "Uf72c" = "pageUp:"; "Uf72d" = "pageDown:"; }

    That is: no errors. I'm still running on trial license. Fix this problem for me, and I'll pay for TextMate :-)

    /M

  12. 10 Sep 2005 | # Mikkel Rasmussen wrote…

    Whoops!

    Seems like your post-a-comment thingy took the redirection character (<) and started a HTML tag :-/ So the rest of my post was blown away. Maybe you should fix this :-)

    To summarize: The test yielded no errors. Does anyone have a clue, why it only works for some people?

    /M

  13. 10 Sep 2005 | # Allan Odgaard wrote…

    Mikkel: I presume you ran pl on the file to verify the integrity, cause what's shown lacks backslashes and uses semi-smart quotes (but that might just be the post form — which btw is not written by me, so I'm not going to look into having it escape accidental HTML characters).

    As for the actual file, it should be in ~/Library and not /Library — I think you've placed it in the latter (based on the prompt).

    I haven't tested if other apps also look for it in all the normal library places, if they do, TM should be improved to do so as well.

  14. 12 Sep 2005 | # Mikkel Rasmussen wrote…

    Allan: Yup, you're right. My mistake! Apparently I didn't capture the tilde (~) when I copied the path. But now it works :-) (Tested in TM and Mail).

    Great stuff for us Multi-platform users. (Windows/*nix at work, Mac at home).

    Cheers! /M

  15. 03 Oct 2005 | # Felix wrote…

    Those interested in using the key bindings feature without manually editing the plist file, might enjoy TextMacro. It is a preference pane that allows to do just that.

    I have been using it ever since I switched to the Mac. More details along with TextMacro itself can be found at:

    http://www.mai.liu.se/~milan/TextMacro/

    Enjoy. Felix

  16. 25 Oct 2005 | # CP wrote…

    Oh man… I'm going to try this when I get home. If this actually works you are my new hero!

  17. 12 Nov 2005 | # Chris wrote…

    Guys, just a quick THANKS for these solutions — both the dict file tweak (which worked great for me) and the TextMacro pointer (which I'll try on the next Mac I run into). I'd already searched three times for a solution to this before finally coming across this page. It's great to have my keyboard nav back!

  18. 09 Dec 2005 | # Nate Beaty wrote…

    I wasn't able to get Allan's example to validate. I just spent a good hour fussing around with trying to make my own, and then finally got TextMacro to work.

    Not sure why I couldn't get my key bindings to work with ASCII, but here's my Terminal output:

    [veronica]$ pwd /Users/natebeaty/Library/KeyBindings [veronica]$ more DefaultKeyBinding.dict { \"\UF729\" = \"moveToBeginningOfLine:\"; \"$\UF729\" = \"moveToBeginningOfLineAndModifySelection:\"; \"\UF72B\" = \"moveToEndOfLine:\"; \"$\UF72B\" = \"moveToEndOfLineAndModifySelection:\"; \"\UF72C\" = \"pageUp:\"; \"\UF72D\" = \"pageDown:\"; }

    [veronica]$ pl

  19. 09 Dec 2005 | # Nate Beaty wrote…

    Argh, guess I should have realized the < would eat the rest of my post after "pl" — this was pl's output:

    2005-12-08 15:39:24.523 pl[9889] *** Exception parsing ASCII property list: NSParseErrorException XML parser error: Unexpected character { at line 1 Old-style plist parser error: Expected terminating '}' for dictionary at line 2

  20. 09 Dec 2005 | # Allan Odgaard wrote…

    After upgrading to WordPress 1.5, all my quotes are now prefixed with a backslash :(

    The example should I give above should NOT have escaped quotes, i.e. it should be (using single quotes, which work as well):

    {
        /* home */
        '\UF729'  = 'moveToBeginningOfLine:';
        '$\UF729' = 'moveToBeginningOfLineAndModifySelection:';
     
        /* end */
        '\UF72B'  = 'moveToEndOfLine:';
        '$\UF72B' = 'moveToEndOfLineAndModifySelection:';
     
        /* page up/down */
        '\UF72C'  = 'pageUp:';
        '\UF72D'  = 'pageDown:';
    }
    
  21. 21 Dec 2005 | # Steven Chanin wrote…

    I'm able to get the example shown to work, but I can't seem to add any key bindings to it to depend on the command key.

    I am trying to add two emacs like bindings: command-d — forward delete word command-backspace — backward delete word

    I started by copying and pasting everything from the example above. That works fine (e.g. home, shift home, page up, page down, etc). I then added my two additional key bindings (note: i replaced the double quotes with * to hopefully avoid the problems other people had above)

    *@d*  = *deleteWordForward:*;
    *@\U007F*  = *deleteWordBackward:*;
    

    and they don't do anything. So then after much experimentation, I had the idea of change the @ to a ~ and trying the option key.

    Lo and behold, they started working.

    Has anyone seen anything like this before? Is @ (shift-2) actually the right modifier to represent the command key?

    Thanks.

  22. 22 Dec 2005 | # Allan Odgaard wrote…

    Steven: 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 (⌘⌫).

  23. 24 Dec 2005 | # sjk wrote…

    [off-topic alert]

    Greetings,

    I just started exploring the MacroMates site last night and this first post is mostly to make a quick suggestion:

    Since many "code" fragments and other stylized text is posted here it would be very useful having comment previewing to help ensure they'll display as intended. Any chance of adding that? Thanks!

    Some personal background:

    I'm approaching TextMate from the perspective of an experienced, long-time Emacs veteran (since its original TECO implementation on MIT-ITS). My Emacs usage has been less on OS X compared with other systems and I haven't really been comfortable with other editors; e.g. trying TextWrangler was enough to know BBEdit ain't for me. So, I want to use this as a window of opportunity to give TextMate a chance to become my primary editor on OS X. Based on what I've seen so far it has a chance… if I can learn to successfully drive it from the keyboard, like Emacs. I don't need it to be my mail client or anything overly esoteric like that to be satisfied.

  24. 27 Dec 2005 | # Allan Odgaard wrote…

    sjk: while certainly a good idea, I'm running WordPress as the blog engine, and am not involved in its development (although I did go through the source this month to submit fixes for the various text mangling bugs, so hopefully there'll be less problems with this in the future :) ).

    As for keyboard usage, I personally do everything from the keyboard :)

  25. 30 Dec 2005 | # sjk wrote…

    Thanks for the feedback, Allan. Wasn't sure if my post would get noticed, which can be an issue for weblogs without mail notification.

    Re: TextMate Blog. Are you saying this blog is hosted by a third party so you don't have directly control over which features it has? If you do have control or influence, the two main WordPress comment preview plugins I'm aware of are:

    Live Comment Preview <http://dev.wp-plugins.org/wiki/LiveCommentPreview&gt; Sample @ <http://www.timgaden.com/hawkwings/2005/12/31/tapdex-one-tap-access-to-address-book-contacts/&gt;

    Filosofo Comments Preview <http://www.ilfilosofo.com/blog/comments-preview/&gt; Sample @ dev. site

    Just the simple live comment preview would be a useful addition here (IMO).

    Re: TM keyboard usage. Would a personalized combination of Cocoa NSResponder class action methods (described here, several which I've been using for years), Application Keyboard Shortcuts (via System Preferences), and TM macros be a recommended strategy to get the most complete keyboard functionality?

    I'm also interested in hearing from Emacs users about their transition experiences with TM. I found a few Emacs-related forum threads and some random Wiki comments but nothing too significant. My first hurdle is discovering how to do some common things as easily in TM as I can in Emacs. I expect some to require learning new "TM-ways" and others via Emacs-like emulation (e.g. with keybindings and macros).

    Anyway, I could really be posting more about this on the forum instead of here so I'll stop now. And the forum's got comment previewing and mail notification that the blog lacks.

  26. 02 Jan 2006 | # Allan Odgaard wrote…

    sjk: I can install plug-ins — I'll check out the WP preview stuff when I find the time, thanks.

    The key bindings route sounds about right. I know Brad Miller (sometimes on ##textmate) has a bundle that recreates most of the Emacs stuff he was missing, though with time I think this bundle has shrunken in size.

  27. 22 Jan 2006 | # AD wrote…

    One character code to add to your table – I looked everywhere for this!

    \UF739 Clear/Num Lock key

    If anyone else out there has one of these compact graphite keyboards with no forward delete key, the way to map one to your Clear key is:

    { /* clear key becomes forward delete */ "\UF739" = "deleteForward:"; }

  28. 24 Jan 2006 | # Don Park wrote…

    this worked beautifully. the article should have a comment about how this is not a textmate configuration but a system-wide configuration. Now all my text editing apps work how i expect. yea!

  29. 24 Apr 2006 | # Marc Logemann wrote…

    awesome blog entry with all the nice comments. Unfortunately TextMacro doesnt work for Inte Macs at this point, but editing the keybindings by hand is a non-issue. I also created my own Keyboard layout file to do some more advanced stuff. In one day i will get this crazy mac kayboard to behave like my old win PC ;-)

    Only the @ cant be solved. Anyone living in germany will understand my issue with the @ <g>.

    Marc

  30. 30 Apr 2006 | # Alfredo Jahn wrote…

    I am looking for a fuller emacs binding. I tried binding "setMark" and "deleteToMark" but they don't seem to work for me. I did bind ^_ to undo and that worked. What am I doing wrong? Do I have to have a selection to run "deleteToMark"? I have:

    $ pl < DefaultKeyBinding.dict { "^3" = "setMark:"; "^_" = "undo:"; "^w" = "deleteToMark:"; }

    Do I have to map ^w to "selectToMark" followed by "deleteToMark"? Can that be done?

    Also, one last question. Are there bundles available, or complete examples on how to get more emacs bindings? BTW, I just love TextMate. Thanks for a great product!

    Alfredo

  31. 01 May 2006 | # Allan Odgaard wrote…

    Alfredo: TextMate does not presently support the various mark selectors, sorry (it’s a noted request, and should happen eventually).

  32. 22 May 2006 | # Edward Ocampo-Gooding wrote…

    Is there a key binding for "find as you type" / incremental search?

  33. 22 May 2006 | # Allan Odgaard wrote…

    Edward: Yes, that’s:

    "^s" = "ISIM_incrementalSearch:"; 
    "^S" = "ISIM_reverseIncrementalSearch:";
    
  34. 31 May 2006 | # Colin Biggin wrote…

    I'm just switching from CW and I use option-tab for going between header/source files (actually, this might be a hold-over from Think… enough dating myself) and I can't get out of this habit.

    I've tried editing the .nib and changing keyboard shortcuts and those don't work. Can I do it using these bindings (and if so, how)?

    Colin

  35. 01 Jun 2006 | # Allan Odgaard wrote…

    Colin: The menu system itself will only act on command keys (⌘) which is why changing the Nib doesn’t work.

    The action method is goToFileCounterpart: so you want to create a DefaultKeyBinding.dict file containing something like this:

    {
       "~\033" = "goToFileCounterpart:";
    }
  36. 12 Jul 2006 | # porneL wrote…

    linked article on apple.com = 404

  37. 15 Jul 2006 | # Justin W wrote…

    Thanks for posting this, this was a big help to me, as I can't reach escape for auto-complete without straining.

  38. 18 Jul 2006 | # Mike wrote…

    i tracked down the corresponding code for the Help key (UF746) and created the ~/Library/KeyBindings/DefaultKeyBinding.dict (in my home dir if that gets stripped), but nothing I change the Help key to seems to take. I tried the same remapping against the Clear key and it works fine. Any way to modify the behaviour of the Help key? FWIW, I did quit my test app (TextEdit) and tried relogging to see if it would help. No dice.

    Thanks, Mike

  39. 19 Jul 2006 | # Allan Odgaard wrote…

    Mike: The Help key is rather special in that for Cocoa applications it is used more as a state modifier.

    Meaning if you click the Help key, the mouse pointer turns into a question mark, and now the next mouse click is “special” in that it requests help for the clicked item.

    This is handled before the key event is seen by the focused control, which is the one which resolves key events based on your key bindings, so there is no way to change the behavior of Help using those.

    The same applies to command keys (⌘) in that these are handled by teh menu system, again before the focused control sees the key event, so these are also not useable in key bindings files.

  40. 19 Jul 2006 | # Mike wrote…

    Bummer. Thanks, Allan.

  41. 11 Aug 2006 | # Jeff Hamilton wrote…

    There is also a GUI editor for KeyBindings.dict files available at http://www.cocoabits.com/KeyBindingsEditor that works pretty well.

  42. 26 Aug 2006 | # Jacob Rus wrote…

    I should note this here for posterity, though most people have already seen it. I wrote an article which explains all this key binding stuff in far more detail. Many many emacs bindings are achievable, for emacs aficionados, though for most of it, there are also TextMate native commands which do the same or similar, and would probably be a better choice for sticking with the community.

    Anyway, though emacs mark/point bindings still don't work in textmate, multiple keystroke bindings and multiple action bindings allow relatively complex behavior, and between bindings, commands, and macros, emacs users (and anyone else), should be able to get TM to just about whatever they want.

  43. 26 Aug 2006 | # David G. Kay wrote…

    I'd like to switch to Text Mate, but I depend on my own idiosyncratic set of keystroke bindings (they're similar to emacs bindings, with multi-key sequences and mark-setting, but the actual keys are different). I have these set up using the DefaultKeyBindings.dict file; they work fine in most apps. But in TextMate, I find that they conflict with some already-defined bindings. I haven't gone through them all, but for example, I bind ^g to move-right, and TextMate binds it to change-case. (Actually, it seems to change-case AND move right.)

    So, two questions: First, is there some way to make my bindings override the default TextMate ones (short of painstakingly going through the whole list, looking for each in TextMate, and redefining each one by hand using the Keyboard preference pane or TextMacro or KeyboardEdit or something)? And to follow up, is there a TextMate command that lists every current key binding?

    Second, is support of emacs-style mark-setting anticipated at some point?

    Many thanks,

    –DGK

  44. 26 Aug 2006 | # Allan Odgaard wrote…

    David: See the key bindings section of the manual for how you can basically replace the key bindings dictionary TM uses to augment the standard key bindings.

    As for marks: it’s on my to-do, but a lot of things are on my to-do.

  45. 27 Aug 2006 | # David G. Kay wrote…

    I gather that this is the relevant paragraph:

    In addition TextMate has a /path/‍to/‍TextMate.app/‍Contents/‍Resources/‍KeyBindings.dict file with some extra key bindings which are specific to TextMate (and thus not appropriate to put in the per user global key bindings file). You can copy this file to ~/Library/‍Application Support/‍TextMate and edit it, this will then take precedence over the bundled file.

    But I can't find the KeyBindings.dict file mentioned. I tried to search for it, and I tried to open the Textmate.app package with Pacifist (which gave me an error).

    What am I missing?

    –DGK

  46. 27 Aug 2006 | # Allan Odgaard wrote…

    David: Pacifist is for looking into installer packages. You need only right-click the TextMate application and select Show Folder Contents or use Terminal to look inside it.

    The file you want to copy to ~/Library/Application Support/… is found as TextMate.app/Contents/Resources/KeyBindings.dict.

  47. 27 Aug 2006 | # David G. Kay wrote…

    Okay, that's great. I've got it nearly all set now. The one snag I'm hitting is ^H, which I want to map to a backspace (deleteBackward:). I have the entry in the KeyBindings.dict file, but in TextMate I get a little popup message saying "can't find documentation." Is there some way to override that?

    –DGK

  48. 27 Aug 2006 | # Allan Odgaard wrote…

    David: That key is in the Shell Script bundle (see other section of the Key Bindings chapter) — however, many languages overload ⌃H for their language, so you may need to remove this from all bundles corresponding to languages you use.

    Btw: please use the mailing list for further support.

  49. 10 Nov 2006 | # Claudioq wrote…

    Well, the trick is powerful and very very awesome, but in firefox doesn't function at all, maybe because it isn't a Cocoa app… but Great Trick!

  50. 24 Nov 2006 | # dc wrote…

    it would be nice if this applied to terminal (without resorting to vi mode)

  51. 16 Dec 2006 | # Jacob Rus wrote…

    dc: go look for Allan's other post, which explains how to get your favorite bindings applied to the terminal.

    Claudioq: it does work in Camino though! And I think that in some upcoming of Firefox they'll make it work (maybe in 3.0?)

  52. 12 Jan 2007 | # Juan Pablo Pincheira wrote…

    I love this article! It worked for me. Thanks!

  53. 28 Jan 2007 | # Frank Reiff wrote…

    I'm a bit stunned that there isn't a UI for changing even the basic key bindings in a texteditor_!?

    Surely this is going to change sooner rather than later?

  54. 06 Mar 2007 | # Jacob Rus wrote…

    frank: you can make macros to change most of them. but this stuff will really work in all cocoa apps.

  55. 21 Oct 2007 | # Dave wrote…

    Oh my god. You've just made me very happy. I have to go between Windows at work to my Mac at home and have been so frustrated at the differences in behavior. Thank you!

  56. 30 Oct 2007 | # Brian wrote…

    Download KeyFixer. This is an automated patch you can download if you don't want to edit the bindings file.

    http://www.starryhope.com/tech/apple/2006/keyfixer/

  57. 09 Dec 2007 | # JiHO wrote…

    In Leopard's Terminal.app, the default key bindings for Home and End send you to the beginning and end of the buffer. This breaks this hack and seems useless since there already are Keyboard Shortcuts for this (⌘↖ and ⌘↘). To change this, go to Terminal's Preferences > Settings > Keyboard Tab. Look for the end key and change it to 'send string to shell:' and type ^E (Control+E) in the box below. Do the same with home and ^A. Now Terminal will behave as any other Application in this respect.

    ^E and ^A are shortcuts that work in any Cocoa applications BTW (thanks to jptix on ##textmate for the info).

  58. 08 Jan 2008 | # LF wrote…

    Personally I'd rather not go mucking with the default keybindings if possible. I'm perfectly happy to use the existing available keystrokes if they are available. I had some difficulty finding them though, which was the frustrating part for me.

    Though I did finally find them: http://hcs.harvard.edu/~jrus/Site/System%20Bindings.html

    For reference the following default bindings will perform the desired actions, and move the caret.

    Home: Command Arrow-Up End: Command Arrow-Down

    PageUp: Command PageUp PageDown: Command PageDown

    Word Left: Option Arrow-Left Word Right: Option Arrow-Right

    and my new favorite:

    Previous Block: Option Arrow-Up Next Block: Option Arrow-Down

    The shift modifier works with all of the above to select.

  59. 08 Jan 2008 | # LF wrote…

    (Markdown is evil btw)

    And I forgot:

    Line Begin: Command Arrow-Left

    Line End: Command Arrow-Right

  60. 01 Mar 2008 | # spawrks wrote…

    \ doesnt work as a keybinding in textmate… anyone else get this to work? I've tried unicode, manual editors.. everything i can never get it to recognize \ for anything

  61. 15 Apr 2008 | # lhn wrote…

    This does not work on leopard. Any hints?

  62. 16 Apr 2008 | # Allan Odgaard wrote…

    spawrks: You’ll need to escape \, i.e. make it \\. If it still fails, post an example demonstrating the problem.

    lhn: Still works for me (on Leopard).

  63. 27 Aug 2008 | # Kelvin wrote…

    This fix (on Leopard) seems to drive my page up/down crazy.

    It still seems to want to "animate" the page up/down at the same time is trying to move the cursor, and so many times it confuses itself. I want something that works as cleanly as opt+pageup/down which doesn't animate.

    Could this have anything to do with my keyboard? I'm using a Macally Icekey keyboard. Which is supposed to be made for macs…

  64. 17 Sep 2008 | # coderguy wrote…

    Works perfectly on my Hackint0sh.

    But is missing the feature of "jump words".

    I could archieve this using the following code:

    /* jump words */
    "@\UF702" = "moveWordLeft:";
    "@\UF703" = "moveWordRight:";
    
    /* jump words with selection */
    "$@\UF702" = "moveWordLeftAndModifySelection:";
    "$@\UF703" = "moveWordRightAndModifySelection:";
    
  65. 10 Oct 2008 | # Anonymous wrote…

    what about keyboard maestro?

  66. 04 Feb 2009 | # Plamen wrote…

    Hello, I tried everything written in here and I managed to make Home and End buttons to work.

    However Home-Shift, End-Shift won't do anything but a "beep" sound. The cursor wouldn't even move.

    Please help…What could be the problem?

  67. 04 Oct 2009 | # David Troyer wrote…

    lovely.

  68. 17 Oct 2009 | # Steve wrote…

    Finding this was the perfect start to resolving my challenge, but then I stumbled upon an even easier solution:

    http://www.cocoabits.com/KeyBindingsEditor/

    While it's simple enough to edit ~/Library/KeyBindings/DefaultKeyBinding.dict, this little freebie app simplifies the process by providing not only a GUI frontend, but more importantly, it reveals all the actions available.

    If you already had created a DefaultKeyBinding.dict file, you might want to back it up before using the program, as it overwrites it with a different format.

    Muscle memory is persistent, isn't it? Enjoy.

  69. 18 Oct 2009 | # Steve wrote…

    Please excuse the last post: it's a redundant reference to the Cocoabits KeyBindingsEditor (noticed after submitting that someone had already mentioned it… oops)

  70. 04 Nov 2009 | # RC wrote…

    Ok, I just tried this on my buddy's computer and I gotta say that was super rad. I cannot the underestimate the importance of the 'Home' and 'End' keys (having switched from Windows.)

  71. 21 Dec 2009 | # roger wrote…

    Alt-PageUp and Alt-PageDown still have the functions I would like to use but it seems that they are no longer mapped to pageUp: or :pageDown in Snow Leopard. At least the given keymappings do not work anymore on Snow Leopard.

  72. 12 Jan 2010 | # Jeff R wrote…

    Thanks!

    I don't know if it's just that I've spent so much time in Windows, but I do rely on the home and end keys.

    But LF's link to the Cocoa key bindings really helps; now that I know what the standard Cocoa keys are, it shouldn't take too much time to rework the muscle memory.

Comments closed, you can use the mailing list for discussion.