Modifying the cocoa text system to suit your needs.

Hello.

I can’t find where we discussed this, about reconfiguring key-bindings. I just want to state, that if you watch the vido about XCode from wwdc 2012, then you too will hear the encouragment of playing with them, and configuring. :slight_smile: They actually will refer you to the Cocoa Eventhandling guide in the video.

I can tell you that I now have a control-l that selects a paragraph in all my cocoa applications.

(You’ll get the correct documents up front when you google for “modify cocoa text key bindings”. The docs from harvard.edu are good! -But a bit old, where you see NextStep like property lists starting and ending with parenthesis, then you know should create an array with plist editor, unless of course you see it is a key-value pair, then you’ll create a dictionary.

Of course you’ll start off by putting a copy of the StandardKeybindings file you are referred to in the Cocoa Event Handling guide into your ~/Library/Keybindings directory, -which comes premade, before you change something.

I just write this, because it is useful to know that you can fix this, should you wish to use some special characters often, or you have a great idea about what you want to work in a standardized way throughout your applications.

Edit

Say you have an urge to edit xml or html with TextEdit, using keybindings that supports that, the way you want it,
then nothing hinders you in saving the original keybindings file, and copy in the one with key bindings for xml/html editing, firing up textEdit, and then restoring the keybindings file back to the normal. Then you can edit xml with TextEdit, and all your other apps works normally, as the keybindings file is only read during startup of the application.

Hello.

For those interested in knowing how to make the ^l mark a line:

I removed the entry for ^l, that was there since I never use “center selection”, then I added a new array I believe you can change the existing string for centering the selection in the plist file into an array, and then just add two childs, which should be named item 0 and item 1 respectively.

Item 0 should have a contents of moveToBeginningOfParagraphAndModifySelection:
item 1 should have moveToEndOfParagraphAndModifySelection: as its contents. (Colons are included.)

This was of course all done on my private defaultKeyBindings.dict file, and it started to work immediately after I had restared TextEdit. :slight_smile:

BBEdit comes with such a key by default, and that is where I got the idea from, you really miss ^l once you have gotten used to it. :slight_smile:

I think a complete listing of available commands should be in the Docs for the Cocoa Text System.

The web pages from harvard.edu, is a very good starting point, for seeing what is possible, it is possible to create two key press commands like ctrl-k b for instance.

Hello.

If you are having trouble modding bindings for instance for Emac’s goto and swap mark for instance, and you are having a foreign (non-us) keyboard layout, the culprit may very well be that the control-@ keystroke that are used to set the mark, is laying upon a function of some file device deep down, and effectively makes control-@ into a dead key.

I solved it by remapping that function to the keystroke control-m. :slight_smile:

Hello.

Hindsightly: the problem with control-@ was that I didn’t escape it in the dictionary (xml format) with a \ so that the specifier for control-@ looked like ^@ well, I must have overlooked somewhere that the at sign should be escaped, because it is really a place holder for the command key without escaping. I guess apple don’t recommend this, or they would otherwise have documented it in the cocoa text system.

Doing the modifications, are on the other hand worthwhile in my experience: I type for instance esc u for uppercase esc l for lower case and esc c for capitalize. I also type opt ctrl h to remove everything from say a save dialog.