Mac – Lion: Map Option + arrow to home/end

keyboardmac

I am using the CLI version of Vim on Mac mini, with OS X Lion.

I use Vim as my main code editor, and one thing that bother me is lack of Home and End keys for moving to the Start and End of lines, respectively.
(On my laptop, the arrow keys left and right are home and end, with the Fn modifier)

I know Control + Arrows move screens, and Command + Arrows move through windows, so any way I can I can get Option or Fn + Arrows to do this?

I would really like something like this across all applications.

EDIT:

I answered this myself by basically following: theandystratton.com/2009/… I used the values supplied in the second comment too, which worked in both Vim and in general terminal too.

I wonder is there any drawbacks to using this…?

Best Answer

To remap home and end in Terminal, run f=~/Library/Preferences/com.apple.terminal.plist; plutil -convert xml1 $f; open $f -e, and change this:

<key>F729</key>
<string>scrollToBeginningOfDocument:</string>
<key>F72B</key>
<string>scrollToEndOfDocument:</string>

To this:

<key>F729</key>
<string>&#x1b;OH</string>
<key>F72B</key>
<string>&#x1b;OF</string>

To change them in normal text views, create ~/Library/KeyBindings/ and save a property list like this as DefaultKeyBinding.dict:

{
    "\UF729" = moveToBeginningOfParagraph:;
    "\UF72B" = moveToEndOfParagraph:;
    "$\UF729" = moveToBeginningOfParagraphAndModifySelection:;
    "$\UF72B" = moveToEndOfParagraphAndModifySelection:;
}

Another option would be to use KeyRemap4MacBook. See the "Use PC Style Home/End (except in Virtual Machine,RDC)" setting in https://raw.github.com/tekezo/KeyRemap4MacBook/master/Tests/lib/string/data/checkbox.xml.