Commands used with the Korn shell vi and emacs mode.
vi mode
< Esc > k then use your h,j,k,l vi type commands
What you've typed can be recalled again on the command line
so that you can just press 'Enter' to re-execute the command.
Commands can then be edited, too. Just use your vi skills.
__ Details __
The history of commands is kept in the user's directory as
$HOME/.history.
First the user needs to log in using the Korn shell, which is the
default shell for new users. The user's $HOME/.profile needs to
contain the lines:
EDITOR=vi
export EDITOR
Make those changes, then make them happen by running your .profile:
. ~/.profile
Go ahead and type a few harmless commands like 'cal' and 'banner hello'
to prime your history file; then you are ready to use it. When you want
to work with a command in your history, press the 'Esc' key once. This
puts you into a single line vi editor, in command mode, that has opened
your history file. To cycle up or down through the commands in your
history, use the 'j' and 'k' keys just as you would in vi. When you find
the command you want, press Enter.
Because you are using a single line vi, you can use all the usual
vi commands to move about and alter the command as needed. Things
to try are the search '/' keystroke in order to search through your
history for the command you are looking for and the 'w' or 'b' keystrokes.
emacs mode
The equivalent for emacs style editing is
set -o emacs
or
EDITOR=emacs
export EDITOR
or ksh invocation as
ksh -o emacs
The playback and editing keys are then the normal movement sequences
^P, ^N, ^B, ^F, ^A, ^E.
Use of Arrow keys can be enabled in ksh88 and previous with the
following set in your ~/.profile
# fn keys for ansi terminal or xterm alias
__A='^P' # UpArr alias
__B='^N' # DwnArr alias
__C='^F' # RghtArr alias
__D='^B' # LftArr alias
__H='^A' # Home
( The ^x form here is the real control character)
---------------
for ksh93 and later the above will not work instead you need:
# test for ksh93 - (dropped ERRNO)
set keybinding handling
[[ ${ERRNO:-unset} == "unset" ]] && {
alias array='typeset -A'
typeset -A KeyTable
trap 'eval "${KeyTable[${.sh.edchar}]}"' KEYBD
function keybind # key [action]
{
typeset key=$(print -f "%q" "$2")
case $# in
2) KeyTable[$1]=' .sh.edchar=${.sh.edmode}'"$key"
;;
1) unset KeyTable[$1]
;;
*) print -u2 "Usage $0 key [action]"
return 2 # usage errors return 2 by default
;;
esac
}
keybind $'\t' $'\E\E' # Tab -> file/cmd completion
keybind $'\E[A' $'\020' # up
keybind $'\E[B' $'\016' # down
keybind $'\E[C' $'\006' # right
keybind $'\E[D' $'\002' # left
keybind $'\E[H' $'\001' # beginning of line 'Home'
keybind $'\E[Y' $'\005' # 'End' of line
<mschalit@pacbell.net>
<hops@sco.com>
gerberb@zenez.com
|