Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Global Emacs Key Bindings for OS X

Emacs keybindings everywhere in Mac OS X

by lelf

Update: there’s some more

I feel very sorry for you’re emacser on mac and haven’t got anything in ~/Library/KeyBindings/

Crash course:

  • Get this file: Emacs Opt Bindings.dict

  • Edit it (optionally), — it’s self-explainary. Then save (creating the directory if there isn’t one) as ~/Library/KeyBindings/DefaultKeyBinding.dict

  • ...

  • PROFIT! Enjoy, for example your ⌥F doing forward-word. Everywhere. Well, mostly.

Applications will pick this up after restaring (apps, not computer).

P.S.

It should look like this

{ "f" = "moveWordForward:"; "b" = "moveWordBackward:"; "<" = "moveToBeginningOfDocument:"; ">" = "moveToEndOfDocument:"; }

© 2013 Anton Nikishaev Generated by Hakyll, don't edit! All rights strawberry preserved.

{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
* BEWARE:
* This file uses the Option key as a meta key. This has the side-effect
* of overriding Mac OS keybindings for the option key, which generally
* make common symbols and non-english letters.
*/
/* Ctrl shortcuts */
"^l" = "centerSelectionInVisibleArea:"; /* C-l Recenter */
"^/" = "undo:"; /* C-/ Undo */
"^_" = "undo:"; /* C-_ Undo */
"^ " = "setMark:"; /* C-Spc Set mark */
"^\@" = "setMark:"; /* C-@ Set mark */
"^w" = "deleteToMark:"; /* C-w Delete to mark */
/* Incremental search. */
/* Uncomment these lines If Incremental Search IM is installed */
/* "^s" = "ISIM_incrementalSearch:"; /* C-s Incremental search */
/* "^r" = "ISIM_reverseIncrementalSearch:"; /* C-r Reverse incremental search */
/* "^g" = "abort:"; /* C-g Abort */
/* Meta shortcuts */
"~f" = "moveWordForward:"; /* M-f Move forward word */
"~b" = "moveWordBackward:"; /* M-b Move backward word */
"~<" = "moveToBeginningOfDocument:"; /* M-< Move to beginning of document */
"~>" = "moveToEndOfDocument:"; /* M-> Move to end of document */
"~v" = "pageUp:"; /* M-v Page Up */
"~/" = "complete:"; /* M-/ Complete */
"~c" = ( "capitalizeWord:", /* M-c Capitalize */
"moveForward:",
"moveForward:");
"~u" = ( "uppercaseWord:", /* M-u Uppercase */
"moveForward:",
"moveForward:");
"~l" = ( "lowercaseWord:", /* M-l Lowercase */
"moveForward:",
"moveForward:");
"~d" = "deleteWordForward:"; /* M-d Delete word forward */
"^~h" = "deleteWordBackward:"; /* M-C-h Delete word backward */
"~\U007F" = "deleteWordBackward:"; /* M-Bksp Delete word backward */
"~t" = "transposeWords:"; /* M-t Transpose words */
"~\@" = ( "setMark:", /* M-@ Mark word */
"moveWordForward:",
"swapWithMark");
"~h" = ( "setMark:", /* M-h Mark paragraph */
"moveToEndOfParagraph:",
"swapWithMark");
/* C-x shortcuts */
"^x" = {
"u" = "undo:"; /* C-x u Undo */
"k" = "performClose:"; /* C-x k Close */
"^f" = "openDocument:"; /* C-x C-f Open (find file) */
"^x" = "swapWithMark:"; /* C-x C-x Swap with mark */
"^m" = "selectToMark:"; /* C-x C-m Select to mark*/
"^s" = "saveDocument:"; /* C-x C-s Save */
"^w" = "saveDocumentAs:"; /* C-x C-w Save as */
};
}
@lipi

This comment has been minimized.

Copy link

@lipi lipi commented Jun 25, 2016

Using alt/option as meta: enable 'use option as meta key' in Terminal / Preferences / Keyboard

@MyoThuraZaw

This comment has been minimized.

Copy link

@MyoThuraZaw MyoThuraZaw commented Nov 9, 2019

It does not work in MacOS Catalina. Please kindly update the gist.

@kbroderick

This comment has been minimized.

Copy link

@kbroderick kbroderick commented Dec 13, 2019

It does not work in MacOS Catalina. Please kindly update the gist.

It works for me, at least for M-f / M-b / M-d in Chrome (which are the ones I most often use and thus the ones I tested). I just created a ~/Library/KeyBindings folder and put this in it as DefaultKeyBinding.dict.

@bozakov

This comment has been minimized.

Copy link

@bozakov bozakov commented May 12, 2020

I can confirm M-f / M-b / M-d don't seem to work in Catalina with a German layout (works with 'use option as meta key' in Terminal). Any suggestions to get this system-wide?

@iCodeSometime

This comment has been minimized.

Copy link

@iCodeSometime iCodeSometime commented Aug 1, 2020

Works for me on Catalina

@jooize

This comment has been minimized.

Copy link

@jooize jooize commented Aug 2, 2020

While creating a Swedish variant of Colemak keyboard layout I had the issue that DefaultKeyBinding.dict had no effect on certain keys. Appears that the keys need to have an output with the modifiers that are pressed when DefaultKeyBinding.dict is supposed to override that same effectively unused output. An entry ~< in DefaultKeyBinding.dict with character < at Shift-, in the keyboard layout requires an output for the key at Shift-Option-, in the keyboard layout. Any idea for how to output nothing for a key yet still enough to satisfy macOS to trigger the Cocoa DefaultKeyBinding.dict? I'm using Ukelele to create the keyboard layout, but could manually edit it.

Append 2020-08-27:
In keyboard layout, I map as output for all keys I do not use for symbols on the Option layer. I map as output for all keys I do not use for symbols on the Shift-Option layer.

@atfzl

This comment has been minimized.

@fkgruber

This comment has been minimized.

Copy link

@fkgruber fkgruber commented Oct 14, 2020

Thanks, very useful.
How do we get the C-s C-r C-g to work? The comments say we need Incremental search IM installed. Where do we find this? Google didn't give any clear answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.