Add 'twiddle characters' support to Cocoa apps

Oct 28, '04 09:37:00AM

Contributed by: smichr

There have been several previous hints regarding keybindings. This one will explain how you can activate the BBEdit-like 'twiddle' command, which transposes two adjacent characters. Since 'transpose' is an action which may be bound to keystrokes, it is possible to add the following line to your user's Library -> KeyBindings -> DefaultKeyBinding.dict file and get the twiddle feature in Cocoa applications:

  "^`" = ("moveBackward:", "transpose:"); /* bbedit twiddle */
Since transpose acts on the characters to the left and right of the cursor, the moveBackward command allows one to place the cursor to the right of the characters to be transposed. Pressing Control-` will then transpose them and leave the cursor in its initial position (transpose moves the cursor forward).

There's a nice reference to the keybinding key syntax in a KeyBinding article on CocoaDev.com, and a list of actions that may be bound to keystrokes can be found in Apple's NSResponder documentation.

[robg adds: I didn't have either the folder or the file noted above. However, simply creating them and then adding the command worked perfectly -- TextEdit now twiddles the characters as described. If this stuff interests you, you can see some of the previous hints on keybindings with this search or this search -- there will be some overlap between the two, but they should cover all the keybinding hints.]

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041026211641708