May 19, 2015

I've customized my default key bindings on Mac to try and get some conformity amongst my many platforms. I tend to get confused, and these make it easier for me each time I switch around.

For one thing, this fixed the Home and End keys' default behavior. Also tweaked PgUp and PgDown slightly. Then also added shortcuts for the most commonly-used CTRL-<key> variants (like copy and paste).

I've added/created the following file: (also creating the directory)
~/Library/KeyBindings/DefaultKeyBinding.dict

With the text content:

/* ~/Library/KeyBindings/DefaultKeyBinding.dict */

{
      /* Remap Home / End to be correct :-) */
      "\UF729"  = "moveToBeginningOfLine:";                   /* Home         */
      "\UF72B"  = "moveToEndOfLine:";                         /* End          */
      "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
      "$\UF72B" = "moveToEndOfLineAndModifySelection:";       /* Shift + End  */

      /* And map old behavior to Ctrl-Key */
      "^\UF729"  = "moveToBeginningOfDocument:";                   /* Ctrl + Home         */
      "^\UF72B"  = "moveToEndOfDocument:";                         /* Ctrl + End          */
      "^$\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Ctrl + Shift + Home */
      "^$\UF72B" = "moveToEndOfDocumentAndModifySelection:";       /* Ctrl + Shift + End  */

      /* Fix PgUp and PgDown to move cursor :-) */
      "\UF72C"  = "pageUp:";                        /* PgUp */
      "\UF72D"  = "pageDown:";                      /* PgDown */
      "$\UF72C" = "pageUpAndModifySelection:";      /* Shift + PgUp */
      "$\UF72D" = "pageDownAndModifySelection:";    /* Shift + PgDown */

      /***** DELETE-INSERT(HELP) KEYS *****/

      /* Note that the Windows "insert" key is the Mac "help" key */
      "$\UF728"   = "cut:";                           /* Shft-FwdDel  Cut */   
      "^\UF746"   = "copy:";                          /* C-Help       Copy */
      "$\UF746"   = "paste:";                         /* Shft-Help    Paste */


      /***** RETURN KEY *****/
      "$\U000A"   = "insertLineBreak:";               /* Shft-Ret     Line break */

      "^\UF702"   = "moveWordLeft:";                  /* C-left       Move word left */
      "^\UF703"   = "moveWordRight:";                 /* C-right      Move word right */

      /***** ARROWS *****/
      "$^\UF702"  = "moveWordLeftAndModifySelection:"; /* C-Shft-left  Select word left */
      "$^\UF703"  = "moveWordRightAndModifySelection:"; /* C-Shft-right Select word right */


      /***** CTRL + LETTERS *****/

      "^a"        = "selectAll:";                     /* C-a          Select all */

      "^x"        = "cut:";                           /* C-x          Cut */
      "^c"        = "copy:";                          /* C-c          Copy */
      "^v"        = "paste:";                         /* C-v          Paste */

      "^z"        = "undo:";                          /* C-z          Undo */
      "^y"        = "redo:";                          /* C-y          Redo */

      "^s"        = "save:";                          /* C-s          Save */
      "^S"        = "saveAs:";                        /* C-Shift-s     Save as */
      "^p"        = "print:";                         /* C-p          Print */
}