Korn Shell: End, pgup, pgdown, and delete key not working

5,883

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
  esac
}
trap keybd_trap KEYBD
set -o emacs
Share:
5,883

Related videos on Youtube

drayman
Author by

drayman

Updated on September 18, 2022

Comments

  • drayman
    drayman over 1 year

    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.

  • drayman
    drayman almost 12 years
    Thank you for the help. But now I'm getting an error that says .kshrc: line 6: syntax error: ')' unexpected
  • drayman
    drayman almost 12 years
    Right where the keybd_trap () { part is.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 12 years
    @shix Sorry, there was a typo (an extra parenthesis on each case line), fixed now.
  • drayman
    drayman almost 12 years
    Wow! Thank you so much. I've had this problem for a while now.