AutoPair functionality using Cocoa KeyBindings
I’ve been using the application “AutoPairs” since it was mentioned on 43folders some time ago. Yesterday (via the Macromates TextMate blog) I found an article on the Cocoa Text System and realised I could recreate AutoPairs’ functionality by just using native Cococa Keybindings found in OSX.
Add these lines to your ~/Library/KeyBindings/DefaultKeyBinding.dict (create the file if it isn’t already there) and the commands will be available in every application started afterwords.
/* Recreate Auto pairs functionality */
"\\\"" = ( "insertText:", "\"\"", "moveBackward:" );
"(" = ( "insertText:", "()", "moveBackward:" );
"~(" = ( "insertText:", "{}", "moveBackward:" );
"~8" = ( "insertText:", "[]", "moveBackward:" );
"<" = ( "insertText:", "<>", "moveBackward:" );
When you type e.g ⇧2 for a double quote (as in swedish keyboard layout), it’ll automatically insert the ending quote as well and place the cursor between them. This will also work for “([{<”. Remember the shortcuts are for a swedish keymap so you might want to change that.
A real time saver when writing outside an editor without this functionality built-in (like TextMate).
Simplfied the commands based on Jacob Rus’ comment.
Tue 11/7/06, 12:39
Nice! Awesome! Great!
Det blir inte krock i textmate så att det inte blir dubbelt i textmate osv?
/
Tue 11/7/06, 13:12
Nope för TextMate kör en egen textarea istället. Men t.ex. TextEdit, Mail etc funkar det i.
/
Sat 5/8/06, 08:22
you can more easily do this as follows:
(”insertText:”, “()”, “moveBackward:”)
/
Mon 7/8/06, 10:46
Thanks Jacob Rus. I’ve updated the post to use the simplier commands instead.
/
Wed 10/1/07, 10:30
Hi! Very nice site! Thanks you very much! JjYBAPZNiWhqlZ
/
Wed 10/1/07, 23:11
Hi! Very nice site! Thanks you very much! QgSBhoGp0t6L
/
Wed 31/1/07, 23:23
bcvomwcml
/