User Name
Password
AppleNova Forums » General Discussion »

What's in your KeyBindings.dict?


Register Members List Calendar Search FAQ Posting Guidelines
What's in your KeyBindings.dict?
Thread Tools
Majost
monkey with a tiny cymbal
 
Join Date: Nov 2004
Location: Lost
 
2008-10-30, 03:16

Alright, so tonight I randomly stumbled across a few amazingly useful additions to OS X's default keybindings.

For the uninitiated, OS X has a really great text input system. There are a whole slew of control sequences that are built-in and extremely useful. For example, control-a moves to the beginning of a line; control-e to the end. Simple, and handy... and you can type them without leaving the keyboard for the mouse or arrow keys. They're based on the keybindings from Emacs. And they work in all Cocoa apps that use the built-in text handling (most of them). Here are all the commands that are built-in.

The real beauty is how these things can be extended with a simple dictionary file, located in ~/Library/KeyBindings/DefaultKeyBinding.dict (create the folder and file if they don't exist). For a great explanation (and a lot of these examples), check out Jacob Rus' site.

I've known about this capability for a while, but I just discovered some really neat applications for it.

For example, you can assign one keystroke to embed the previous word into an HTML/XML tag pair. If I write strong and then hit control-<, it automagically becomes <strong>|</strong>, with the caret at the | position!

Even better: You can set up command sequences. I have it set up so that hitting 'option-g' followed by 'a' displays the Greek α, 'option-g' 'W' is Ω, etc. You could set up an equivalent series for HTML entities or the LaTeX codes or what not.

One of the default sequences is that if you ever want a symbol that is obscured by these keybindings (e.g. 'option-g' is originally ©), you can prepend that keystroke with 'control-q'.

Anyhow, here's my full DefaultKeyBinding.dict file. Anyone else have nifty addenda that they use? Or is this just way too geeky?

Code:
{ /* Ctrl shortcuts from Emacs that aren't defaults */ "^l" = "centerSelectionInVisibleArea:"; /* C-l Recenter */ "^/" = "undo:"; /* C-/ Undo */ "^_" = "undo:"; /* C-_ Undo */ "^ " = "setMark:"; /* C-Spc Set mark */ /* TextMate-like addenda */ "^w" = "selectWord:"; /* C-w Select the current word */ "^t" = "transpose:"; /* C-t Transpose the adjacent chars */ "^u" = "uppercaseWord:"; /* C-u Make current word ALL CAPS */ "^U" = "lowercaseWord:"; /* C-U Make current word all lowercase */ /* This command will let Ctrl-< turn the previous word * into an HTML/XML opening and closing tag pair. */ "^<" = ( "setMark:", "moveWordBackward:", "deleteToMark:", "insertText:", "<", "yank:", "insertText:", ">", "setMark:", "insertText:", "</", "yank:", "insertText:", ">", "swapWithMark:"); /* Option-key (Meta) shortcuts from Emacs*/ "~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:"); "~d" = ( "setMark:", "moveWordForward:", "deleteToMark:"); /* M-d Delete word forward */ "^~h" = ( "setMark:", "moveWordBackward:", "deleteToMark:"); /* M-C-h Delete word backward */ "~\U007F" = ( "setMark:", "moveWordBackward:", "deleteToMark:"); /* M-Bksp Delete word backward */ "~t" = "transposeWords:"; /* M-t Transpose words */ /* My meta additions */ "~l" = "selectLine:"; "~p" = "selectParagraph:"; "~y" = "yankAndSelect:"; /* C-x shortcuts from Emacs*/ "^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 */ }; /* Get rid of command-right and left arrow, preventing them from overriding * real commands (Back / Forward). Use ^a and ^e for this instead. */ "@\UF702" = "noop:"; "@\UF703" = "noop:"; /* The Greek Alphabet */ "~g" = { "a" = ("insertText:", "\U03B1"); /* a alpha */ "b" = ("insertText:", "\U03B2"); /* b beta */ "g" = ("insertText:", "\U03B3"); /* g gamma */ "d" = ("insertText:", "\U03B4"); /* d delta */ "e" = ("insertText:", "\U03B5"); /* e epsilon */ "~e" = ("insertText:", "\U03F5"); /* M-e epsilon var */ "z" = ("insertText:", "\U03B6"); /* z zeta */ "h" = ("insertText:", "\U03B7"); /* h eta */ "q" = ("insertText:", "\U03B8"); /* q theta */ "~q" = ("insertText:", "\U03D1"); /* M-q theta var */ "i" = ("insertText:", "\U03B9"); /* i iota */ "k" = ("insertText:", "\U03BA"); /* k kappa */ "l" = ("insertText:", "\U03BB"); /* l lambda */ "m" = ("insertText:", "\U03BC"); /* m mu */ "n" = ("insertText:", "\U03BD"); /* n nu */ "x" = ("insertText:", "\U03BE"); /* x xi */ "o" = ("insertText:", "\U03BF"); /* o omicron */ "p" = ("insertText:", "\U03C0"); /* p pi */ "r" = ("insertText:", "\U03C1"); /* r rho */ "~r" = ("insertText:", "\U03F1"); /* M-r rho var */ "~s" = ("insertText:", "\U03C2"); /* M-s final sigma */ "s" = ("insertText:", "\U03C3"); /* s sigma */ "t" = ("insertText:", "\U03C4"); /* t tau */ "u" = ("insertText:", "\U03C5"); /* u upsilon */ "f" = ("insertText:", "\U03C6"); /* f phi */ "~f" = ("insertText:", "\U03D5"); /* M-f phi var */ "c" = ("insertText:", "\U03C7"); /* c chi */ "y" = ("insertText:", "\U03C8"); /* y psi */ "w" = ("insertText:", "\U03C9"); /* w omega */ "A" = ("insertText:", "\U0391"); /* A Alpha */ "B" = ("insertText:", "\U0392"); /* B Beta */ "G" = ("insertText:", "\U0393"); /* G Gamma */ "D" = ("insertText:", "\U0394"); /* D Delta */ "E" = ("insertText:", "\U0395"); /* E Epsilon */ "Z" = ("insertText:", "\U0396"); /* Z Zeta */ "H" = ("insertText:", "\U0397"); /* H Eta */ "Q" = ("insertText:", "\U0398"); /* Q Theta */ "I" = ("insertText:", "\U0399"); /* I Iota */ "K" = ("insertText:", "\U039A"); /* K Kappa */ "L" = ("insertText:", "\U039B"); /* L Lambda */ "M" = ("insertText:", "\U039C"); /* M Mu */ "N" = ("insertText:", "\U039D"); /* N Nu */ "X" = ("insertText:", "\U039E"); /* X Xi */ "O" = ("insertText:", "\U039F"); /* O Omicron */ "P" = ("insertText:", "\U03A0"); /* P Pi */ "R" = ("insertText:", "\U03A1"); /* R Rho */ "S" = ("insertText:", "\U03A3"); /* S Sigma */ "T" = ("insertText:", "\U03A4"); /* T Tau */ "U" = ("insertText:", "\U03A5"); /* U Upsilon */ "F" = ("insertText:", "\U03A6"); /* F Phi */ "C" = ("insertText:", "\U03A7"); /* C Chi */ "Y" = ("insertText:", "\U03A8"); /* Y Psi */ "W" = ("insertText:", "\U03A9"); /* W Omega */ }; }
  quote
atomicbartbeans
reticulating your mom
 
Join Date: Jan 2005
Send a message via AIM to atomicbartbeans  
2008-10-30, 22:03

Your 'select line' and 'select paragraph' additions are awesome. I made a .dict file with those two but it's not working. Do I have to reboot or something?
  quote
Majost
monkey with a tiny cymbal
 
Join Date: Nov 2004
Location: Lost
 
2008-10-31, 00:18

Quote:
Originally Posted by atomicbartbeans View Post
Your 'select line' and 'select paragraph' additions are awesome. I made a .dict file with those two but it's not working. Do I have to reboot or something?
You should just need to restart the application.
  quote
atomicbartbeans
reticulating your mom
 
Join Date: Jan 2005
Send a message via AIM to atomicbartbeans  
2008-10-31, 09:35

Oho, you're right!

So cool...
  quote
Majost
monkey with a tiny cymbal
 
Join Date: Nov 2004
Location: Lost
 
2008-11-01, 16:41

Nobody else uses this? Really? I just find it so amazingly useful. Especially if you remap caps lock to control.

There's just one downside: I can't type on Windows or Linux. <control>-w is particularly bad.
  quote
atomicbartbeans
reticulating your mom
 
Join Date: Jan 2005
Send a message via AIM to atomicbartbeans  
2008-11-01, 17:22

Well honestly, I never knew about the ability to define new keyboard commands until I read this thread.

If it's any consolation, I use the 'select line' command ALL the time now.

You ask me for a hamburger.
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools

« Previous Thread | Next Thread »

All times are GMT -5. The time now is 14:18.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova