There are several ways to change key bindings in XNEdit. The easiest way to add a new key binding in XNEdit is to define a macro in Preferences -> Default Settings -> Customize Menus -> Macro Menu. However, if you want to change existing bindings or add a significant number of new key bindings you will need to do so via X resources.
Before reading this section, you must understand how to set X resources (see the help section "X Resources"). Since setting X resources is tricky, it is also helpful when working on key-binding, to set some easier-to-verify resource at the same time, as a simple check that the XNEdit program is actually seeing your changes. The appres program is also very helpful in checking that the resource settings that you make, actually reach the program for which they are intended in the correct form.
Keyboard commands are associated with editor action routines through two separate mechanisms in XNEdit. Commands which appear in pull-down menus have individual resources designating a keyboard equivalent to the menu command, called an accelerator key. Commands which do not have an associated menu item are bound to keys via the X toolkit translation mechanism. The methods for changing these two kinds of bindings are quite different.
The most general way to bind actions to keys in XNEdit is to use the translation table associated with the text widget. To add a binding to Alt+Y to insert the string "Hi!", for example, add lines similar to the following to your X resource file:
XNEdit*text.Translations: #override \n\ Alt<Key>y: insert_string("Hi!") \n
The Help topic "Action Routines" lists the actions available to be bound.
Translation tables map key and mouse presses, window operations, and other kinds of events, to actions. The syntax for translation tables is simplified here, so you may need to refer to a book on the X window system for more detailed information.
Note that accelerator resources (discussed below) override translations, and that most Ctrl+letter and Alt+letter combinations are already bound to an accelerator key. To use one of these combinations from a translation table, therefore, you must first un-bind the original menu accelerator.
A resource for changing a translation table consists of a keyword; #override, #augment, or #replace; followed by lines (separated by newline characters) pairing events with actions. Events begin with modifiers, like Ctrl, Shift, or Alt, followed by the event type in <>. BtnDown, Btn1Down, Btn2Down, Btn1Up, Key, KeyUp are valid event types. For key presses, the event type is followed by the name of the key. You can specify a combination of events, such as a sequence of key presses, by separating them with commas. The other half of the event/action pair is a set of actions. These are separated from the event specification by a colon and from each other by spaces. Actions are names followed by parentheses, optionally containing one or more parameters separated by comas.
The menu shortcut keys shown at the right of XNEdit menu items can also be changed via X resources. Each menu item has two resources associated with it, accelerator, the event to trigger the menu item; and acceleratorText, the string shown in the menu. The form of the accelerator resource is the same as events for translation table entries discussed above, though multiple keys and other subtleties are not allowed. The resource name for a menu is the title in lower case, followed by "Menu", the resource name of menu item is the name in lower case, run together, with words separated by caps, and all punctuation removed. For example, to change Cut to Ctrl+X, you would add the following to your .Xdefaults file:
nedit*editMenu.cut.accelerator: Ctrl<Key>x nedit*editMenu.cut.acceleratorText: Ctrl+X
Accelerator keys with optional shift key modifiers, like Find..., have an additional accelerator resource with Shift appended to the name. For example:
nedit*searchMenu.find.acceleratorText: [Shift]Alt+F nedit*searchMenu.find.accelerator: Alt<Key>f nedit*searchMenu.findShift.accelerator: Shift Alt<Key>f