Version 3 (modified by judah, 6 years ago)

--

Custom Key Bindings

As of version 0.4.1, the user may specify custom key bindings in their .haskeline file. The two new settings are:

  • bind: <key> <key> (bind the first key to the actions of the second key)
  • keyseq: <term> <string> <key> (POSIX-only: add a new key sequence)

where <term> is a terminal name (optional), <string> is Haskell string syntax, and <key> is either:

  • a single character
  • f<n> (a function key)
  • left, right, down, up
  • backspace, delete, home, end, killline
  • return, tab, escape
  • ctrl-<key>, shift-<key>, meta-<key>

Note that the meta- key is ALT on Windows.

These features are pretty new, so feedback and suggestions are encouraged.

Examples

The following lines will cause the backspace key to move one character to the left nondestructively, and meta-backspace to delete the character to the left of the cursor:

bind: backspace left
bind: meta-backspace backspace

Control-left/right

The following instructions will make ctrl-left and ctrl-right skip words.

First, we check KeyBindings to see that M-B and M-F are bound by default to the commands we want. So the necessary bind commands are:

bind: ctrl-left meta-b
bind: ctrl-right meta-f

That's sufficient on Windows, but for POSIX systems a couple more steps are needed. Normally Haskeline looks up a key sequence in the system terminfo database; however ctrl-left and ctrl-right don't have a standard capability name, so Haskeline needs to be told manually what their key sequence is.

To find out their control sequences, you can do something like:

$ ghc -e getLine
<press ctrl-left, then return>^[[5D
"\ESC[5D"
$ ghc -e getLine
<press ctrl-right, then return>^[[5C
"\ESC[5C"

Thus we add the following lines (which will be ignored on Windows):

keyseq: "\ESC[5D" ctrl-left
keyseq: "\ESC[5C" ctrl-right

Finally, we may want to restrict the above key sequences to a given terminal (as selected by the $TERM variable). For example, on my system I have:

keyseq: xterm-color "\ESC[5D" ctrl-lefT
keyseq: xterm-color "\ESC[5C" ctrl-right
keyseq: xterm "\ESC[1;5D" ctrl-left
keyseq: xterm "\ESC[1;5C" ctrl-right

since $TERM==xterm-color means I'm using OS X's Terminal.app program, and $TERM==xterm means I'm using the X11 xterm program.