haskell / haskell/haskeline

[Feature request] Alternatives to Esc/Alt + key for vi mode

Open
#27 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
247
Forks
82
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm used to using vi mode for pretty much anything I can. The thing is, the way I use vi is by entering Alt+key combinations to go into normal mode instead using the –in my opinion– burdensome Esc key. This works in quite a few terminal emulators including Linux's non-graphical TTYs (usually accessed with Alt+Ctrl+Fn).

However, this trick does not work with haskeline since it interprets Esc instantly followed by a key `k` as `metaKey k`. This makes haskeline based UIs (in my case, mainly ghci) very cumbersome to use for me, and if I had to guess, a few others too.

I'm currently going around this issue by simply commenting out the part of the code responsible for this behaviour like so:

``` diff
diff -ur System.orig/Console/Haskeline/Backend/Posix.hsc System/Console/Haskeline/Backend/Posix.hsc
--- System.orig/Console/Haskeline/Backend/Posix.hsc 2014-12-23 03:32:27.000000000 +0100
+++ System/Console/Haskeline/Backend/Posix.hsc 2015-09-20 20:04:31.849770372 +0200
@@ -193,10 +193,10 @@
lexKeys baseMap cs
| Just (k,ds) <- lookupChars baseMap cs
= k : lexKeys baseMap ds
-lexKeys baseMap ('\ESC':cs)
--- TODO: what's the right thing ' to do here?
- | k:ks <- lexKeys baseMap cs
- = metaKey k : ks
+-- lexKeys baseMap ('\ESC':cs)
+-- -- TODO: what's the right thing ' to do here?
+-- | k:ks <- lexKeys baseMap cs
+-- = metaKey k : ks
lexKeys baseMap (c:cs) = simpleChar c : lexKeys baseMap cs

lookupChars :: TreeMap Char Key -> [Char] -> Maybe (Key,[Char])
```

I then recompile GHC, and, since I don't use any Alt shortcuts anyway, all is fine for me.

Still, I feel it would be nice if there was an option to change this behaviour at runtime, perhaps by letting the user enter a sequence like Ctrl-v + Alt-`k` while in insert mode, which would be interpreted "verbatim" as Alt-`k`.

Would you be interested in implementing such a functionality, or at least would you be prepared to accept a pull request providing it? Please let me know. In the latter case, I will see what I can do but might have to ask you a few questions for guidance.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.