Hi > I want to use home, end, delete, pageup, pagedown with ksh. My TERM is > xterm-color. These keys works fine with tcsh and zsh, but not with ksh > (print a tilda ~) > > I found this: > > bind '^[[3'=prefix-2 > bind '^[[3~'=delete-char-forward > bind '^[[1'=prefix-2 > bind '^[[1~'=beginning-of-line > bind '^[[4'=prefix-2 > bind '^[[4~'=end-of-line > > But when I set one bindkey, the last does not work anymore. > > How can I use these keys in ksh with a .kshrc ?
First of all I'm not a ksh expert, so anyone feel free to correct me if I'm wrong or I have overlooked something. This is my understanding of your problem (this is all assuming 7-bit input, I have no idea what is possible if you use 8-bit): When you press some of the function keys, xterm generates a sequences of four characters. For Page Up this is '^[[5~', where ^[ is the usual representation of the ESC character (ASCII 27). However, in ksh, key bindings may only consist of one, two or three characters, with some limitations on two and three character input. A key binding may be a prefix (one of a choice of two, or none) and a key (the man page says "a control character optionally preceded by one of the two prefix characters" but it in fact doesn't seem to have to be a control character). By default, the two prefixes are: prefix-1 is ^[. xterm puts a ^[ before the key when you use the Alt key (so Alt-A is '^[A' - the actual Esc key also generates ^[ which is why Esc then A does the same things as Alt-A). So when you press Alt-A, xterm generates '^[A', then ksh consumes the '^[' as prefix-1 and looks for the key binding for prefix-1 + A which is beginning-of-line. prefix-2 is ^X, ^[[ and ^[O. This allows three character sequences to be bound. For example, the Down key causes xterm to send '^[[B' (note the extra [ which differentiates it from Alt-B). The ^[[ is consumed by ksh as prefix-2 and then it looks for prefix-2 + A, which is up-history. ^[O is used in a similar way. So, you can bind three character sequences so long as the first two characters match prefix-2. This works for the arrow keys, F1-F4 (by default) and probably a few others I forget. For me, Home and End generate ^[[H and ^[[F (you can check they do for you as well by running cat then pressing the keys, if they don't let me know, I might have fiddled with some setting), so you should be able to bind them with: bind '^XH'=beginning-of-line bind '^XF'=end-of-line (ksh always uses ^[ for prefix-1 and ^X for prefix-2 when adding and displaying key bindings.) However, the other keys you are interested in (Page Up/Page Down) generate a four character sequence with a trailing ~. If you try the same trick with them, the key will work, but because ksh only consumes the first three characters you will be left with a stray ~ in your input. >From what I've found out so far, there is no way to make ksh eat that trailing ~ and still be able to tell the difference between the keys. It is possible to (use a hack to) bind ONE key with a trailing ~ by binding the start to prefix-2 and then binding ~ itself to the command, I do this for the Del key. On OpenBSD Del generates Backspace by default but I'd rather it didn't so I turn that off with 'XTerm*deleteIsDEL: false' in .Xdefaults. Then it generates '^[[3~' instead. To bind this, you can first bind '^[[3' (prefix-2 then 3) as a macro to send prefix-2 again, this means that to ksh, the '^[[3' will look like prefix-2. Then bind prefix-2 plus ~ to delete-char-forward: bind -m '^X3'=^X bind '^X~'=delete-char-forward I don't know if you can persuade xterm to send different sequences for Page Up and Page Down, there may be a knob somewhere among its million options. This may allow you to bind the keys in ksh, but will probably stop them working with other applications. Hope this helps, Nicholas