So basically my End, Pageup/Pagedown, and Delete key are not working in ksh93. I'm running FreeBSD by the way.

My arrow keys are working, and so is my home key.

Those keys work when I put this in my .kshrc

set -o emacs

I have tried doing THIS, by putting this in my .kshrc. To make the End key work.

alias __Y=`echo "\005"`     # end = ^e = end of line

I opened up vim, and pressed Ctrlv, and typed 005. And the ^E showed up. Still, nothing worked.

Anyone know anyway to get those key to work?

Also, When ever I press those keys it prints out a ~. I also know that I could use Ctrld, or Ctrla, I do NOT want to use these.


That answer is specific to certain terminal emulators, I don't think it can be generalized outside Solaris.

In ksh, press Ctrl+V then End. This will insert a literal escape character followed by the rest of the escape sequence that the key sends. For example, you might see ^[[4~ (the ^[ at the beginning is in fact an escape character, not ^ followed by [). Do the same for the other cursor keys you want to reconfigure.

In your .kshrc, set a KEYBD trap to translate the escape sequences from the function keys into the bindings for the commands you want the key to invoke. For example (you may need to adjust the escape sequences — note that inside $'…',\e` means an escape character):

keybd_trap () {
  case ${.sh.edchar} in
    $'\e[1~') .sh.edchar=$'\001';; # Home = beginning-of-line
    $'\e[4~') .sh.edchar=$'\005';; # End = end-of-line
    $'\e[5~') .sh.edchar=$'\e>';; # PgUp = history-previous
    $'\e[6~') .sh.edchar=$'\e<';; # PgDn = history-next
    $'\e[3~') .sh.edchar=$'\004';; # Delete = delete-char
trap keybd_trap KEYBD
set -o emacs
  • Thank you for the help. But now I'm getting an error that says .kshrc: line 6: syntax error: ')' unexpected – shix Jul 11 '12 at 2:25
  • Right where the keybd_trap () { part is. – shix Jul 11 '12 at 2:25
  • 1
    @shix Sorry, there was a typo (an extra parenthesis on each case line), fixed now. – Gilles Jul 11 '12 at 7:33
  • Wow! Thank you so much. I've had this problem for a while now. – shix Jul 11 '12 at 17:41

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.