MacOS – Same shortcuts across input sources

keyboardmacos

OS X by default supports emacs key bindings, for example Ctrl+A to go to the beginning of the line, My problem is when I switch to a different language these Ctrl key bindings stop working.

Is it possible to either modify the keyboard layout to send English letters when the key is pressed with Ctrl. Or add new binding to OS X that accept the Ctrl binding with the correspoding letters in the other input source. Or is there a third choice?

Best Answer

I tried modifying some non-Latin layouts that came with Ukelele, but couldn't get shortcuts like control+A to work with them. I haven't found a way to get them to work with my custom keyboard layout either, but I'm probably just missing something...

Another option would be to create ~/Library/KeyBindings/ save a property list like this as DefaultKeyBinding.dict:

{
    "^ф" = moveToBeginningOfParagraph:; // ctrl-a on the Russian layout
    "^щ" = (insertNewlineIgnoringFieldEditor:, moveBackward:); // ctrl-o on the Russian layout
    // ...
}

Some of the default control key actions, copied from lri.me/keybindings:

"^p" = moveUp:;
"^n" = moveDown:;
"^b" = moveBackward:;
"^f" = moveForward:;
"^h" = deleteBackward:;
"^d" = deleteForward:;
"^a" = moveToBeginningOfParagraph:;
"^e" = moveToEndOfParagraph:;
"^k" = deleteToEndOfParagraph:;
"^l" = centerSelectionInVisibleArea:;
"^v" = pageDown:;
"^t" = transpose:;
"^y" = yank:;
"^o" = (insertNewlineIgnoringFieldEditor:, moveBackward:);
"^P" = moveUpAndModifySelection:;
"^N" = moveDownAndModifySelection:;
"^B" = moveBackwardAndModifySelection:;
"^F" = moveForwardAndModifySelection:;
"^A" = moveToBeginningOfParagraphAndModifySelection:;
"^E" = moveToEndOfParagraphAndModifySelection:;
"^V" = pageDownAndModifySelection:;
"~^b" = moveWordBackward:;
"~^f" = moveWordForward:;
"~^B" = moveWordBackwardAndModifySelection:;
"~^F" = moveWordForwardAndModifySelection:;