-->
Previous Table of Contents Next


Key Bindings

One useful feature that pdksh supports, which is lacking in the Bourne Again Shell, is key bindings. This feature enables you to change the behavior of key combinations for the purpose of command-line editing.

If, for example, you do not like the fact that you have to use the emacs key sequence Ctrl+P to move up in the history buffer, you can change the key sequence for that command to something else. The syntax for doing the key binding is the following:


bind <key sequence> <command>

This feature effectively enables you to customize pdksh to have the exact feel that you want. One of the most commonly used key bindings is to bind the up, down, left, and right arrows to be used as they are in bash (for scrolling up and down the history list, and for moving left and right along the command line). This binding is typically found in your .kshrc file, which is the startup file for the shell (it is read whenever the shell starts).

The bind commands that are needed to create these bindings are as follows:


bind ‘^[[’=prefix-2

bind ‘^XA’=up-history

bind “^XB’=down-history

bind ‘^XC’=forward-char

bind ‘^XD’=backward-char

Table 12.1 gives some of the most useful editing commands that you can use for binding keys, along with the default binding and a description of each. You can get a listing of all of the editing commands that pdksh supports by typing the bind command without any arguments.

Table 12.1. Useful key bindings for pdksh.

Keystroke Meaning

abort (^G) Used to abort another editing command. It is most commonly used to stop a history list search.
backward-char (^B) Moves the cursor backward one character. This command is often bound to the left arrow key.
backward-word (^[b) Moves the cursor backward to the beginning of a word.
beginning-of-line (^A) Moves the cursor to the beginning of the command line.
complete (^[^[) Tells pdksh to try to complete the current command.
copy-last-arg (^[_) Causes the last word of the previous command to be inserted at the cursor position.
delete-char-backward (ERASE) Deletes the character that is to the left of thecursor.
delete-char-forward Deletes the character to the right of the cursor.
delete-word-backward (^[ERASE) Deletes the characters to the left of the cursor back to the first white space character that is encountered.
delete-word-forward (^[(d) Deletes the characters to the right of the cursor up to the first character that occurs after a white space character.
down-history (^N) Moves down one line in the history list. This command is often bound to the down-arrow key.
end-of-line (^E) Moves the cursor to the end of the current line.
forward-char (^F) Moves the cursor forward one character. This command is often bound to the right-arrow key.
forward-word (^[F) Moves the cursor forward to the end of a word.
kill-line (KILL) Deletes the current line.
kill-to-eol (^K) deletes all of the characters to the right of the cursor on the current line.
list (^[?) Causes pdksh to list all of the possible command names or filenames that can complete the word in which the cursor is currently contained.
search-history (^R) Searches the history list backward for the first command that contains the inputted char-acters.
transpose-chars (^T) Exchanges the two characters on either side of the cursor. If the cursor is at the end of the command line it switches the last two characters on the line.
up-history (^P) Moves up one command in the history list. This command is often bound to the up-arrow key.


Previous Table of Contents Next