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.

Most of my computing time is spent in Linux (with occasional time in Windows). On these platforms the Home and End keys universally jump to the beginning or end of the current line.

I am gradually getting used to using the one Apple computer in my life, but it is still frustrating than these keys seem to be bound to the beginning and end of the document and there doesn't seem to be any key at all for the line based actions.

My question:

  1. Are there existing keybindings I'm missing for beginning and end of line? (I mostly use a Terminal, Chrome and LibreOffice)
  2. Is there a way to rebind the functions of these keys to the functions I am familiar with? I am willing to give up the document based versions which seem of little use to me.

Also two caveats:

  1. I am not the only user on the system. It would be nice if my user settings didn't break other peoples experience. If this isn't possible, I think I probably have the strongest preference!
  2. I do use multiple languages and switch between keyboard layouts, so any solutions would be expected to work even when toggling between multiple keyboard layouts.
share|improve this question
Note that while I ended up finding a solution and answering my own question, I'm open to easier or more versatile solutions. Also the process of discovering this is not clear. For example where do you find key codes and action names if I wanted to remap more keys? Feel free to add answers if you have relevant knowledge! –  Caleb Jun 18 '11 at 9:08

4 Answers 4

up vote 44 down vote accepted

The default shortcuts for moving to beginning or end of (wrapped) lines are ⌘← and ⌘→. ⌥↑ and ⌥↓ or ⌃A and ⌃E move to the beginning or end of unwrapped lines (or paragraphs).

You could remap home and end by creating ~/Library/KeyBindings/ and saving a property list like this as DefaultKeyBinding.dict:

    "\UF729"  = moveToBeginningOfParagraph:; // home
    "\UF72B"  = moveToEndOfParagraph:; // end
    "$\UF729" = moveToBeginningOfParagraphAndModifySelection:; // shift-home
    "$\UF72B" = moveToEndOfParagraphAndModifySelection:; // shift-end

Applying changes requires reopening applications. DefaultKeyBinding.dict is ignored by Xcode, Terminal, and many cross-platform applications.

See Cocoa Text System and my website for more information about the customizable keybindings.

Terminal's keybindings can be customized in Preferences > Settings > Keyboard. \033OH moves to the beginning of a line and \033OF to the end of a line.

share|improve this answer
Thanks @Lri, the extra links and existing bindings were exactly what I was looking for. Also, LibreOffice seems to respond just fine to the remapped keys. –  Caleb Jun 18 '11 at 9:12
+1 for Terminal keybindings –  rymo Dec 13 '13 at 21:56

I'm currently on Lion 10.7.4, and for some strange reason editing the ~/Library/KeyBindings/DefaultKeyBinding.dict didn't work for me.

I have found that the KeyRemap4MacBook System Preferences addon works really well, and you can also re-map a variety of keys with it, without having to edit any text files. E.g. changing the page up / page down keys so the cursor also follows on page up / down.

Just download the addon, and in the System Preferences panel, browse to the For PC Users section, and check Use PC Style Home /End.

Note, I picked (Change Home to Command+Left) instead of (Change Home to Control+A), as if I picked the first, and if the line was wrapped, home would take me to the beginning of the wrapped line, several lines above, instead of taking me to the beginning of the current line.


share|improve this answer
This is the only thing that really works. –  Louis Mar 13 '13 at 21:53
Indeed it works immediately, and it's way easier. Thanks! –  Matthieu Napoli Oct 8 '13 at 19:10
Karabiner is great and also open source –  Jedidja Feb 4 at 17:14

Thanks to this article, I figured out how to re-bind the Home and End keys to line based actions on a per-user basis that works across keyboard layouts.

You need to create a dictionary file with the keycodes and new commands to map to, but first make sure the folder where this will be placed exists by opening a Terminal and running:

$ mkdir -p ~/Library/KeyBindings

Then create or edit the file at ~/Library/KeyBindings/DefaultKeyBinding.dict. If it didn't exist before, add the whole section below. If it does exist, just add the four new rows inside the block.

    "\UF729"  = "moveToBeginningOfLine:";
    "\UF72B"  = "moveToEndOfLine:";
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";

In order to activate the settings you will need to logout of your user and login again.

Note that this covers both the normal action of moving the cursor and the Shift+Home/End combination to select durring cursor movement.

share|improve this answer
THANK YOU! Apple's default home/end usage is an absolutely loony-tunes/maddening standards violation for those of us that operate on a wide variety of platforms! You may have just saved my MacBook from taking a vertical trip off the roof of our office building. :-) –  Brian Knoblauch Oct 9 '12 at 15:41
@BrianKnoblauch: The only saving grace is that this fix is user specific, so you can fix your login to be a sane environment without messing up the poor ignorant Mac only junkies whose computer you are using. –  Caleb Oct 9 '12 at 15:51

I'm using the awesome KeyRemap4MacBook with the custom settings below.

It fixes Home/End in most applications and doesn't screw up iTerm2.

From https://gist.github.com/lhotari/6134223181439b9ed0a1

<?xml version="1.0"?>
<!-- ~/Library/Application Support/KeyRemap4MacBook/private.xml -->
<!-- Custom keyboard mappings for MBP using https://pqrs.org/macosx/keyremap4macbook/ -->
        <name>Lari's PC Style Home/End</name>
        <appendix>(Change Home to Command+Left)</appendix>
        <appendix>(Change End to Command+Right)</appendix>
        <appendix>{{ PC_STYLE_BINDINGS_IGNORE_APPS_DESCRIPTION }}</appendix>
            <autogen>__KeyToKey__ FROMKEYCODE_HOME, KeyCode::HOME, ModifierFlag::SHIFT_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_END,  KeyCode::END,  ModifierFlag::SHIFT_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_HOME, KeyCode::HOME</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_END,  KeyCode::END</autogen>
            <only>EMACS, TERMINAL, X11, ECLIPSE</only>
            <autogen>__KeyToKey__ FROMKEYCODE_HOME, KeyCode::A, ModifierFlag::CONTROL_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_END,  KeyCode::E, ModifierFlag::CONTROL_L</autogen>
            <not>{{ PC_STYLE_BINDINGS_IGNORE_APPS }}</not>
            <autogen>__KeyToKey__ FROMKEYCODE_HOME, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND, KeyCode::CURSOR_UP,    ModifierFlag::COMMAND_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_HOME, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL, KeyCode::CURSOR_UP,    ModifierFlag::COMMAND_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_END,  MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND, KeyCode::CURSOR_DOWN,  ModifierFlag::COMMAND_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_END,  MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL, KeyCode::CURSOR_DOWN,  ModifierFlag::COMMAND_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_HOME,             KeyCode::CURSOR_LEFT,  ModifierFlag::COMMAND_L</autogen>
            <autogen>__KeyToKey__ FROMKEYCODE_END,              KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L</autogen>
share|improve this answer

Your Answer


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.