|Version 2 (modified by judah, 8 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:
- keyseq: <string> <key> (POSIX-only: add a new key sequence)
- bind: <key> <key> (bind the first key to the actions of the second key)
where <string> is a Haskell string 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.
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
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