Key Bindings - ne's manual
Description: ne's manual

Next: Changing Menus, Up: Configuration

### 5.1 Key Bindings

`ne` allows you to associate any keystroke with any command. To accomplish this task, you have to create a (possibly UTf-8) file named `.keys` in your `~/.ne` directory. You can change the default name (possibly specifying a complete path) using the `--keys` argument (see Arguments).

The format of the file is very simple: each line starting with the ‘`KEY`’ sequence of capital characters is considered the description of a key binding. Each line starting with ‘`SEQ`’ binds a character sequence to a key. All other lines are considered comments. The format of a key binding description is

         KEY hexcode command

The hexcode value is the ascii code of the keystroke. (For special keys such as <Insert> or function keys, you should take a look at the file `default.keys` that comes with `ne`'s distribution: it contains a complete, commented definition of `ne`'s standard bindings that you can modify with a trial-and-error approach.) The easiest way to see the code `ne` uses for a given key is by using the KeyCode command. It prompts you to press a key, then reports the code for that key on the status bar.

You can write just the hexadecimal digits, nothing else is necessary (but a prefixing ‘`0x`’ is tolerated). For instance,

         KEY 1 MoveSOL

binds to `<Control>-A` the action of moving to the start of a line, while

         KEY 101 LineUp

binds to the “cursor-up” key the action of moving the cursor one line up.

command can be any `ne` command, including `Escape` (which allows reconfiguring the menu activator) and `Macro`, which allows binding complex sequences of actions to a single keystroke. The binding of a macro is very fast because on the first call the macro is cached in memory. See Macro.

Note that you cannot ever redefine <Return> or <Escape>. This is a basic issue—however brain damaged is the current configuration, you will always be able to exploit fully the menus and the command line.

Besides the “standard” combinations (e.g., `<Control>-`letter), it possible to program combinations based on the <Meta> key (a.k.a. <Alt>). The situation in this case is a bit more involved, because depending on the terminal emulator you are using, the effect of the <Meta> key can be widely different. For instance, `xterm` raises the eighth bit of a character, so, for instance,

         KEY 81 MoveSOF

binds `<Control>-<Meta>-a` to the action of moving to the start of the document. However, `gnome-terminal` will emit the character of ASCII code 1 prefixed with ESC instead (“`\x1b\x01`”). To handle this case, `ne` provides codes from 180 on for simulated <Meta> sequences: for instance,

         KEY 181 MoveSOF

binds the abovementioned sequence to the same action as before. In general, the code 180+x corresponds to the sequence ESC followed by the ASCII character of code x. Note that some of these sequences may be disabled, if they conflict with existing sequences of your terminal (for instance, ESC followed by ‘`O`’ is always disabled because it prefixes several built-in keyboard sequences).

As a final note, we remark that typing `<Meta>-a` on `gnome-terminal` will produce an ESC followed by ‘`a`’ (“`\x1ba`”). Since it is obviously easier to press just <Meta> rather than <Meta> and <Control> at the same time, it is a good idea to associate the same sequence also to this combination, using

         KEY 1E1 MoveSOF

Moreover, this setting provides the user with a second choice: one can press <Escape> followed by a letter instead of using modifiers.

This is the approach used by default in `ne`: this way, <Control> with <Meta> plus a letter should always work, and <Meta> should work sometimes (of course, if you're sure to use always the same kind of emulator you can bind more features). Again, the best place to look at it's `default.keys`.

As stated above, each line starting with ‘`SEQ`’ binds a character sequence to a key code. The format for a ‘`SEQ`’ binding is

         SEQ "sequence" hexcode

where "sequence" is a double-quoted string of characters (which can include escaped hexadecimals) followed by a hexadecimal key code as described above for ‘`KEY`’ definitions.

You should rarely need this, as properly configured systems already do this for most keys. However, some key combinations (<Control> in conjunction with cursor keys for example) are usually not defined. If you know the character sequence your system generates for such a combination, you may use ‘`SEQ`’ to bind that sequence to a particular key code if that sequence isn't already defined on your system. For example, <Control>-“cursor-left” may generate the sequence `\x1b[1;5D`. The following lines bind that sequence to the <F10> key code ‘`14A`’, then bind that key code to the ‘`HELP`’ command.

         SEQ  "\x1b[1;5D"  14A
         KEY  14A          HELP

Sequences are inherently terminal- or terminal emulator-specific, so their utility will vary depending on how many emulators you use. At least they give you the posibility to use keys or key combinations that aren't covered by `curses`.

The key binding file is parsed at startup. If something does not work, `ne` exits displaying an error message. If you want `ne` to skip parsing the key binding file (for instance, to correct the broken file), just give `ne` the `--no-config` argument. See Arguments.