Editing the Cocoa application keyboard mappings

authored by Frank Lynam at 02/10/2013 13:24:50

I like coding in the TextMate text editor when working in OS X but there was always something that used to drive me absolutely mad when using it. Whenever I used the Fn+left arrow or Fn+right arrow key combination, the cursor would move to the start or the end of the current file. Being used to working in other text editors, in which these two key combinations brings you to the start or to the end of the current line, adjusting to TextMate’s interpretation was maddening, especially when it happened for the 20th time that day when working on a huge code file.

Luckily though, there is a workaround. TextMate is a Cocoa application and so it conforms to the Cocoa system keyboard mappings, which can be modified. Here’s how you change the behaviour of the Fn+left arrow to bring you to the start of the current line and the Fn+right arrow to bring you to the end of the current line.

  1. Open terminal.
  2. Check to see if the ~/Library/KeyBindings folder exists. If it doesn’t, create it.
    cd ~/Library/KeyBindings/
    mkdir ~/Library/KeyBindings (if it doesn’t exist)
  3. Now go to ~/Library/KeyBindings
    cd ~/Library/KeyBindings/
  4. Create a file called DefaultKeyBinding.dict
    touch DefaultKeyBinding.dict
  5. Open the file in a text editor and add the following lines.
    	/* home */
    	"UF729"  = "moveToBeginningOfLine:";
    	/* end */
    	"UF72B"  = "moveToEndOfLine:";
  6. Restart TextMate or any other Cocoa application that you are using.
  7. The Fn+left arrow and Fn+right arrow key combinations should now take you to the start or to the end of your file respectively.