Change default textediting keybindings on macOS
On macOS, there are default keybindings for interacting with text like <Ctrl> + t
to swap the places of the characters sourroundig the cursor like this: from “foo ba” to “foo ab”. Another default is that you can move the coursor word-wise, by using the <Option> + <Left or Right arrow key
shortcut. For me it feels more
natural to use the <Ctrl>
key as modifier for this. To change this default, you have to create a ~/Library/KeyBindings/DefaultKeyBinding.Dict
as well as the folder containing it. Here is mine:
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.12.2.
This applies to OS X 10.12.2 and possibly other versions.
Here is a rough cheatsheet for syntax.
Key Modifiers
^ : Ctrl
$ : Shift
~ : Option (Alt)
@ : Command (Apple)
# : Numeric Keypad
Non-Printable Key Codes
Up Arrow: \UF700 Backspace: \U0008 F1: \UF704
Down Arrow: \UF701 Tab: \U0009 F2: \UF705
Left Arrow: \UF702 Escape: \U001B F3: \UF706
Right Arrow: \UF703 Enter: \U000A ...
Insert: \UF727 Page Up: \UF72C
Delete: \UF728 Page Down: \UF72D
Home: \UF729 Print Screen: \UF72E
End: \UF72B Scroll Lock: \UF72F
Break: \UF732 Pause: \UF730
SysReq: \UF731 Menu: \UF735
Help: \UF746
*/
{
"^\UF702" = "moveWordBackward:"; /* Ctrl + LeftArrow */
"^\UF703" = "moveWordForward:"; /* Ctrl + RightArrow */
"^$\UF702" = "moveWordBackwardAndModifySelection:"; /* Ctrl + Shift + Leftarrow */
"^$\UF703" = "moveWordForwardAndModifySelection:"; /* Ctrl + Shift + Rightarrow */
}
I stole and customized Heisencoder's DefaultKeyBinding.Dict and all the helpful comments and lists belong to him.
Read other posts