= Custom Key Bindings = As of version 0.5, the user may specify custom key bindings in their `.haskeline` file. The two new settings are: - {{{bind: }}} (bind the first key to the actions of the second key) - {{{keyseq: }}} (POSIX-only: add a new key sequence) where {{{}}} is a terminal name (optional), {{{}}} is Haskell string syntax, {{{}}} is a space-separated sequence of {{{}}}s, and {{{}}} is either: - a single character - `f` (a function key) - `left, right, down, up` - `backspace, delete, home, end, killline` - `return, tab, escape` - `ctrl-`, `shift-`, `meta-` - `pageup, pagedown` (haskeline>=0.6.2) 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 }}} === Vi-style History === (See ViModeCompatibility.) === 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 ^[[5D "\ESC[5D" $ ghc -e getLine ^[[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. === Sequence macros === Originally suggested by Trent Buck: {{{ bind: { { } left bind: ( ( ) left bind: [ [ ] left bind: } right bind: ] right bind: ) right }}} These bindings automatically closes each opening brace; for example, pressing {{{'('}}} will first insert {{{"()"}}} and then move the cursor one character to the left.