[Korn Shell] Fixing Home, End, pgup, pgdown, and delete keys - General Shell Scripting
When I first started using Korn Shell I found out that my Home, End, pgup, pgdown, and delete keys didn't work like the would in other shells. I started getting really frustrated.

Korn Shell is compatible with bash as a programming language, and has all the interactive capabilities of csh and more.

Today I will show you how to fix this problem.
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.

Open up your .kshrc with vim, and add the following.
Code:
set -o emacs

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

Now you're going to have to edit it.

In vim, remove the '\e[1~', then press CONTROL-V, you'll go into visual mode, now press the Home Key.
Next, you'll want to edit the '\001' in the same line. You do the same as above, press control-V and press 001.
Do the same for the rest.

And that's it. :D Tested in FreeBSD and Slackware.

Note: I noticed that this causes some conflicts with vim in FreeBSD. To fix this do the following.

Code:
nmap <Press control-v and then home here> <esc>0
imap <Press control-v and then home here> <esc>0i
nmap <Press control-v and then end here> <esc>$
imap <Press control-v and then end here> <esc>A




Members  |  Stats  |  Night Mode