Instantly share code, notes, and snippets.

Embed
What would you like to do?
xcode keybindings for emacs emulation
{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* To use: copy this file to ~/Library/KeyBindings/
* after that any Cocoa applications you launch will inherit these bindings
*
* 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 */
"^y" = "yankAndSelect:"; /* C-y Cycle through kill ring */
/* 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 */
};
/* Modifier keys: start with C-m - from mgrimes AT stateful.net */
"^m" = {
"^ " = ("insertText:", "\U2423"); /* C-space space */
"^e" = ("insertText:", "\U21A9"); /* C-e return */
"e" = ("insertText:", "\U2305"); /* e enter */
"^t" = ("insertText:", "\U21E5"); /* C-t tab */
"t" = ("insertText:", "\U21E4"); /* t backtab */
"^d" = ("insertText:", "\U232B"); /* C-d delete */
"d" = ("insertText:", "\U2326"); /* d forward delete */
"^a" = ("insertText:", "\U2318"); /* C-a command (apple) */
"^o" = ("insertText:", "\U2325"); /* C-o option */
"^c" = ("insertText:", "\U2303"); /* C-c control */
"^s" = ("insertText:", "\U21E7"); /* C-s shift */
"s" = ("insertText:", "\U21EA"); /* s caps lock */
"^b" = ("insertText:", "\U2190"); /* C-b solid left */
"^f" = ("insertText:", "\U2192"); /* C-f solid right */
"^p" = ("insertText:", "\U2191"); /* C-p solid up */
"^n" = ("insertText:", "\U2193"); /* C-n solid down */
"b" = ("insertText:", "\U21E0"); /* f dotted left */
"f" = ("insertText:", "\U21E2"); /* b dotted right */
"p" = ("insertText:", "\U21E1"); /* p dotted up */
"n" = ("insertText:", "\U21E3"); /* n dotted down */
"^h" = ("insertText:", "\U2196"); /* C-h home */
"h" = ("insertText:", "\U2198"); /* h end */
"^u" = ("insertText:", "\U21DE"); /* C-u page up */
"u" = ("insertText:", "\U21DF"); /* u page down */
"^x" = ("insertText:", "\U238B"); /* C-x escape */
"x" = ("insertText:", "\U23CF"); /* x eject */
};
}
@nayefc

This comment has been minimized.

nayefc commented Jun 27, 2012

Do I have to do anything other than copying the file? It's not working at all.

@smilingpoplar

This comment has been minimized.

Owner

smilingpoplar commented Jun 27, 2012

copy this file to ~/Library/KeyBindings/
It works on xcode 3.x. I havn't test it on xcode 4.x.

@nayefc

This comment has been minimized.

nayefc commented Jun 27, 2012

That's probably because XCode 4.x has its own key bindings option in preference. I will experiment with that and see how I can get your piece of code to work on that.

@ghost

This comment has been minimized.

ghost commented May 13, 2013

Hey!
Thanks for this. Works perfectly.
I just added Ctrl-Space for "Set mark" in XCode 4. It did code completion on ctrl-space instead of set mark (although other programs, like TextEdit did set the mark correctly).
You have to resolve the conflict it gives with "Show Completions" (just remove that, and use Alt-/ instead for completions).

@chazu

This comment has been minimized.

chazu commented Nov 25, 2013

Forgive me if this is a simple question, but is there a simple way to use alt(option) as meta in this script?

@keenle

This comment has been minimized.

keenle commented Apr 21, 2014

Thanks for complete dict! Works with xCode 5.

@benmathes

This comment has been minimized.

benmathes commented Jan 21, 2015

@chazu alt+keybindings often don't work because osx captures those before they are sent to the app. Alt+f, for example gets you this character: ƒ.
Alt+S: ß
Alt+B: ∫

out of xcode's control :-/

@pelamfi

This comment has been minimized.

pelamfi commented Sep 18, 2015

See here for solutions to the osx capturing alt key problem: http://stackoverflow.com/a/24100077/1148030

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment