2

I'm using the default ksh on OpenBSD 6.2 (based on pdksh) with Vi command line editing mode enabled.

I'm trying to get the arrow keys to work properly as a complement to h, l, j and k (as I'm on a Dvorak keyboard). As far as I can tell, they don't work at all. It does not matter whether I'm in "input" or "command" mode.

The current key bindings includes:

^[[A = up-history
^[[B = down-history
^[[C = forward-char
^[[D = backward-char

These are also the character sequenced produced by my arrow keys if I use Ctrl+VArrow key.

The arrow keys works as expected in Emacs command line editing mode, but as a long time Vi user, I feel somewhat crippled when using it.

My feeling is that the Escape that is sent by the arrow key is interpreted as if I pressed Esc... I get the equivalent behaviour by manually typing e.g. Esc[A as when I press Up-arrow (places me in command mode and then in insert mode at the end of the line).

Question: Has anyone been able to get the arrow keys to work intuitively in Vi-mode in OpenBSD's ksh?

4

I did a quick foray into /usr/src/bin/ksh on my OpenBSD system, seeing as I had the actual sources checked out anyway. I had a cursory glance at c_ksh.c, emacs.c and vi.c and it looks as if the Vi mode was retrofitted into pdksh from nsh at some point (around 1989/1990). The exact words used are

/*      $OpenBSD: vi.c,v 1.55 2018/01/16 22:52:32 jca Exp $     */

/*
 *      vi command editing
 *      written by John Rochester (initially for nsh)
 *      bludgeoned to fit pdksh by Larry Bouzane, Jeff Sparkes & Eric Gisin
 *
 */

The bind-able functions all live in emacs.c, as does the x_bind() function which gets called by the bind builtin, while vi.c seems to have its own implementation of some of them under different names that are not called from x_bind().

Therefore I think I can conclude that the bind builtin is a no-op in Vi-mode in this particular shell.

UPDATE (2018-02-04): After reporting this to the openbsd-misc list, it was confirmed that bind does indeed not do anything in Vi command line editing mode. A patch will go in to modify the ksh manual on OpenBSD so that this is mentioned:

bind string=[editing-command] ...

In Emacs editing mode, the specified editing command is bound to the given string. Future input of the string will cause the editing command to be immediately invoked. Bindings have no effect in Vi editing mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.