Hi Dave,
redirecting from misc@ to tech@ because i'm appending a patch
at the very end, lightly tested.
This has indeed been annoying me for years, but it never occurred
to me that i might be able to figure out what's going on.
Thanks for providing your analysis, i think it's spot on.
So the solution is to not swallow up that escape character, right?
Yours,
Ingo
Dave Cohen wrote on Sun, Aug 07, 2016 at 04:52:50PM -0700:
> I'll try to describe an annoyance with my ksh setup. Web and man
> page searching has not provided a solution. I'm relatively new to
> both ksh and openbsd. I'm on version 5.9 release.
>
> Problem happens when I navigate command history with ctrl-r, then
> use left or right arrow. Hitting left arrow writes "[D", right
> inserts "[C". I'm hitting the arrow keys so I can edit my prior
> command. It's a habit I'm used to that works in bash.
>
> For example to reproduce, let's say I ran "ls -l" but I wanted
> to run "ls -la"...
>
> run the first command, "ls -l".
>
> type "ctrl-r ls". This works as expected, and my cursor is now
> in the middle of "ls -l".
>
> type right arrow. This is where the problem is. The command I'm
> editing becomes "ls[C -l".
>
> From this point, arrow keys work as expected. I can use left or
> right to navigate and edit the command.
>
> If, instead of arrows, I use ctrl-b or ctrl-f, these work fine.
> No artifacts like "[C" or "[D".
>
> If I use bash instead of ksh, this problem does not occur.
>
[...]
> I understand from `man ksh` that these key bindings are defaults:
> bind '^[[C'=forward-char
> bind '^[[D'=backward-char
>
> My assumption is that when in ctrl-r mode, the '^[' is interpreted
> as part of the ctrl-r search (which doesn't match), then the '[C'
> or '[D' is interpreted as the next key (which is inserted). Can
> this behavior be changed?
Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.65
diff -u -p -r1.65 emacs.c
--- emacs.c 26 Jan 2016 17:39:31 -0000 1.65
+++ emacs.c 8 Aug 2016 01:25:13 -0000
@@ -893,9 +893,10 @@ x_search_hist(int c)
if ((c = x_e_getc()) < 0)
return KSTD;
f = kb_find_hist_func(c);
- if (c == CTRL('['))
+ if (c == CTRL('[')) {
+ x_e_ungetc(c);
break;
- else if (f == x_search_hist)
+ } else if (f == x_search_hist)
offset = x_search(pat, 0, offset);
else if (f == x_del_back) {
if (p == pat) {