Update august 4th 2011: Behaviour slightly pooped since Lion (Mac OS X 10.7). Now Home and End act as a back and forward button respectively, unless the cursor is within a text field in your browser.
Nothing I tried worked until I installed KeyRemap4MacBook (http://pqrs.org/macosx/keyremap4macbook).
This installs to your preference pane and the option is found under “For PC Users” and is called “Use PC Style Home/End”.
Everything below this point is useless, and only saved for luls.
This is how I altered ~/Library/KeyBindings/DefaultKeyBinding.dict to change the behaviour of the Home and End keys in Mac OS X 10.6.8. (The directory and file did not exist so I had to create them manually.)
{
/* Remap Home / End to be correct :-) */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}
Copied from http://evansweb.info/2005/03/24/mac-os-x-and-home-end-keys
Mac OS X and Home / End keys
Posted by Jon Evans 24/03/2005 at 14h41
The default key bindings for the home and end keys in Mac OS X are different to any other operating system I’ve ever used. By default, they seem to be bound to the viewport, rather than the line of text you are editing. In a multi-line document, the Home key scrolls up to the top of the document, and the End key scrolls down to the bottom. In each case the caret stays where it was.
As a programmer I find this behaviour to be just plain wrong— I want Home and End to move to the start and end of the current line.
I have found a way to “fix” this problem by editing the default keybindings file,~/Library/KeyBindings/DefaultKeyBinding.dict. Create the directory and / or the file if they’re not already there, and make it look like this:
{ /* Remap Home / End to be correct :-) */ "\UF729" = "moveToBeginningOfLine:"; /* Home */ "\UF72B" = "moveToEndOfLine:"; /* End */ "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */ "$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */ }If there are already entries in DefaultKeyBinding.dict, just add the 4 new mappings above to the main section of your file.
Other more or less relevant sources:
Pingback: 變更 Mac 鍵盤中的 Home/End Key 功能
Thanks for the link to KeyRemap4MacBook, it’s excellent. The support for changing the key repeat speed is also a great feature for power users.
I installed it, but don’t see how to remap the home and end keys to behave like windows. Also, as a new to mac user, how do I create the “DefaultKeyBinding.dict” file? In windows I would have gone to the directory in explorer, used the context menu to create new text file, made the edits and saved as .dict.
I am also a programmer and was looking for a solution for the same reasons you are. The KeyRemap4MacBook is an awesome free tool, but it doesn’t change behavior in Eclipse, which is what I use all the time.
I found something I hadn’t noticed before in Eclipse. In Preferences, under General>Keys, you can remap tons of commands, including got to beginning and end of line. Big help and sigh of relief.
Thanks a lot for the tip. I was going nuts trying to figure out how to fix this in Eclipse.
This also work in TextWrangler under the Keyboard section
@Marty
Thanks a ton for the tip about changing the preferences in Eclipse. I use Spring STS and the Logitech K-750 for Mac and the Home and End keys were driving me nuts! Thanks to your tip, I can now have sane development sessions. 😀
@Marty,
Thanks for the tip about changing the settings in Eclipse. I use Spring STS and the Home and End keys were driving me nuts!!
Thanks again,
John
Pingback: Blog Inventic.eu » Blog Archive » How to hack HOME and END keys on MacOS to behave like on Windows
Thanks for the info on KeyRemap4MacBook. Remapped home/end works great in Sublime Text 2.