Question abount binding a key(sequence) for editline(7)

In vim(1) I have a binding that makes 'jk' act like the ESC (in order to set visual mode). I want to set up this binding for the sh(1) command line editor, editline(7), which can act in the vi-mode as well. The 'bind' command is documented in editrc(5) and the editor commands are documented in editline(7).

So, I tried to accomplish this via both regular binding and with the macro:

1) Regular binding:
Code:
bind "jk" vi-command-mode

Well, it sort of works: when I type 'jk' in the insert mode, the mode is changed into the visual (command) mode. But now it is impossible to type (insert) the 'j' character whatsoever. It now waits until it receives the next character and doesn't print 'j'.

2) Macro:
Code:
bind -s jk ^[

The result is the same as this of the regular binding.

I also tried to find a 'workaround' for this, like:
Code:
bind "jk" vi-command-mode
bind "j" ed-insert
But nope: the last binding overrides the previous one and now 'jk' doesn't switch the editor into the command mode.

Did anyone try to do something similar? Is it even possible?
 
I've been playing with this for a while because I found it interesting and I'm equally stuck. Once you apply any of your configurations, the only way of inserting a "j" character is by pressing ^V before, which is very unpractical. And I have not found any way of accomplishing what you want.
 
I've found what seems a possible way. You have to define all the other combinations: ja, jb, jc, jd, and so on as themselves but with double ^V before each letter.

So, in vim, in your .editrc, you would type, for instance:

bind -s "ja" ^V^Vj^V^Va

But you will see:

bind -s "ja" ^Vj^Va

Now, when you type "j" you still don't see the j, but when you type the "a" afterwards, both the j and the a will appear.

It works also for "j." for instance. The only problem is j+space. This one I don't have a solution for it.

Try with a couple of combinations first. Then add the rest if you see it works for you.
 
For j+space, the only problem with bind -s "j " ^V^Vj^V^V is that the space itself doesn't get inserted, so you will have to type j+space+space. This way it "works."
 
Thank you AlfredoLlaquet, this looks nice! However I think I got something wrong, because when I have this in my .editrc:
Code:
bind -s j ^Vj
bind -s ja ^Vj^Va
I can see 'ja' when I type 'j' and 'a' afterwards, but a single 'j' doesn't print 'j'.

UPD: Oh, I guess that this is actually the drawback that you meant. I.e. that's the reason we want to override all the second characters for 'j'. Though it wouldn't work when we need to type just 'j' and that's it.
 
Thank you AlfredoLlaquet, this looks nice! However I think I got something wrong, because when I have this in my .editrc:
Code:
bind -s j ^Vj
bind -s ja ^Vj^Va
I can see 'ja' when I type 'j' and 'a' afterwards, but a single 'j' doesn't print 'j'.

UPD: Oh, I guess that this is actually the drawback that you meant. I.e. that's the reason we want to override all the second characters for 'j'. Though it wouldn't work when we need to type just 'j' and that's it.
You have to delete the first bind. Leave binds only with two letters: ja, jb, jc, and so on.
 
Back
Top