Filed under: Productivity, Terminal Tips
Remapping Key Combinations
Some people may think I am pro-*nix, but actually I
really just like getting information out there for all our readers. Today I came across a great tip on Switch about Windows-like key bindings. If you don't dig the way Apple has the
start and end key combos mapped
in OS X, you can change them by creating the file ~/Library/KeyBindings/DefaultKeyBinding.dict with the following
contents: /* ~/Library/KeyBindings/DefaultKeyBinding.dict - Home/End keys more like Windows */
{
"\UF729" = "moveToBeginningOfLine:"; /* home */
"\UF72B" =
"moveToEndOfLine:"; /* end */
"$\UF729" =
"moveToBeginningOfLineAndModifySelection:"; /* shift home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* shift end */
"^\UF729" = "moveToBeginningOfDocument:"; /* control home */
"^\UF72B" = "moveToEndOfDocument:";/* control end */
} I personally tested this key binding hack in 10.4.4 and it does work. To test it be sure to quit out of your text application first. Also note that you will have to create a KeyBindings/ directory in your ~/Library/ because it is not there by default. To reverse the key bindings back to normal, just delete the DefaultKeyBinding.dict file you created and restart your text application. If there is a simpler GUI way to create these modifications please post about it in the comments for our readers.
If on the other hand you live in Terminal like me, the start of line and end of line key bindings are Control-A and Control-E respectively. This should feel comfortable to people accustomed to the normal Emacs mode in a shell in other *nix based operating systems.
[via Switch and comments on Ask Slashdot]

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Ty said 6:30PM on 3-13-2006
I'm not getting the best results. End/Home still don't go to the end/beginning of the line in some programs. Is this supposed to go in /Library or ~/Library? 'cause I did both.
Reply
Fabienne Serriere said 6:40PM on 3-13-2006
Ty: it should be in ~/Library. What version of OS X are you running?
Reply
Michael S. said 7:02PM on 3-13-2006
To remap Home and End I needed to open the default key binding file (/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict) and copy and paste the symbols corresponding to Home, End, etc. into Property List Editor (which is what opens when you do "open DefaultKeyBindings.dict")--they look indistinguishable on the screen.
My current DefaultKeyBindings.dict is at http://beebo.org/stuff/mac/DefaultKeyBindings.dict, and includes the Home/End remappings, as well adding in more emacs-like keybindings for Cocoa apps. It's XML for some reason (I think in previous versions it looked like the above). Actually, it's invalid XML: adding in bindings for Home and End makes has made it invalid XML.
Reply
Ernest Leitch said 7:10PM on 3-13-2006
I've been looking for a tip like this for a long time. I'm glad someone figured this out.
Reply
Mark said 7:21PM on 3-13-2006
HOLY TOMATOES, BATMAN!
I posted about this in my blog on March 9th! can you believe i beat TUAW to the post!!??
http://www.ear-fung.us/2006/03/09/home-and-end-key-bindings-in-os-x/
here's another one you might be interested in:
http://www.ear-fung.us/2006/03/13/fs_usage/
it's a little tutorial on how to use fs_usage to show what's going on in the underbelly of OSX.
Reply
Jonathan said 7:27PM on 3-13-2006
You could also download DoubleCommand (http://doublecommand.sourceforge.net) which does this with a GUI along with a whole bunch of other key bindings that can be changed.
Reply
Jeremy said 7:40PM on 3-13-2006
I've never been able to figure out why someone would ever in a million years think that "home" and "end" keys should move to the beginning and end of a line, or why they would want to replicate this completely stupid and broken behavior of Windows.
Reply
Wevah said 9:21PM on 3-13-2006
FWIW, control-A/control-E also work in cocoa text fields/text views, and even a few Carbon applications like BBEdit/TextWrangler.
Reply
Wevah said 9:27PM on 3-13-2006
Now that I read it again, maybe you meant that. Oh, well.
Reply
nezromatron said 9:40PM on 3-13-2006
Jeremy,
And I've never been able to figure out why End should go to the end of the document.. I think my ratio of needing to go to the end of the line vs end of the document is like 5603549465 to 1.
tomayto, tomahto.
Reply
Michael S. said 3:04AM on 3-14-2006
I don't think the Windows Home/End behaviour is strange at all. Scrolling to the beginning/end of the document--and not even moving the cursor!--that's weird.
Reply
Jacob Rus said 4:30AM on 3-14-2006
There are actually a ton of cool things to be done with the Cocoa Text System. I've written extensively about it here:
http://hcs.harvard.edu/~jrus/Site/Cocoa%20Text%20System.html
Also, I made a list of the supported actions here:
http://hcs.harvard.edu/~jrus/Site/selectors.html
One of my favorite things to do:
defaults write -g NSRepeatCountBinding -string "^u"
Reply
Z? said 5:09PM on 3-14-2006
Thanks go out to Jonathan for sharing DoubleCommand as it managed me to do the same without editing any file. By the way, i missed this "feature" of Windows!
Reply
Percy said 10:22AM on 4-05-2006
I added these two lines to mine:
"^$UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* control shift home */
"^$UF72B" = "moveToEndOfDocumentAndModifySelection:";/* control shift end */
This adds Ctrl+Shift+Home/End, since without these two lines it just moves the cursor to top/bottom without selecting as expected.
Reply
won said 10:25AM on 4-05-2006
Part of the reason I as a Mac user don't use Home / End as on Windows is that the default text shortcuts already have this feature in the form of Command-right arrow and Command-left arrow.
Furthermore (and perhaps more useful), on Macs, in text fields, up arrow takes you to the beginning of a line and down arrow takes you to the end.
Reply