shedit

interactive command and history editing in the KornShell

Miscellaneous Information


SYNOPSIS

set -o editmode EDITOR=editprog VISUAL=editprog


DESCRIPTION

By default, the KornShell leaves command line editing to the operating system using these familiar functions. However, these functions are not particularly powerful or friendly. As an alternative, the shell has built-in facilities for interactive command editing and file name generation that not only aid in composing new commands but also provide for convenient modification and re-execution of previous commands. This capability is distinct from that provided by the fc command, which passes previous command lines to a separate program for editing. The built-in facilities mimic the emacs, gmacs, or vi screen editors, and are enabled the following commands (see set and vi for details.)
set -o emacs
set -o gmacs
set -o vi
These facilities are also enabled (with the corresponding option set) by assigning a value ending in emacs, gmacs, or vi to the variable EDITOR or VISUAL (see sh).

Unlike full-screen editors, shell editing uses a one-line window, extending from the end of the prompt to the second-last column. Multi-line history entries are displayed with newlines represented as ^J. The number of columns on the output device is obtained from the COLUMNS variable if defined; otherwise, it is assumed to be 80. A command line that extends into the rightmost column can be scrolled horizontally. If you try to move the cursor beyond the edge of the window, the line is scrolled to approximately centre the cursor in the window. The second last column displays a character marking a scrollable line: < indicates extra data off the left; > indicates extra data off the right; and * indicates extra data off both sides.


EMACS/GMACS EDITING MODE

When this editing mode has been enabled, by any of the means noted earlier, ordinary printable characters from the keyboard are entered in the command line (and echoed). Various control characters introduce command sequences for such things as moving the cursor, scrolling through the command history, and modifying the current command. The only difference between emacs and gmacs mode is in the handling of CTRL-T (see the description of CTRL-T in the Text Change subsection).

The command sequences recognized are listed in functional groups. The notation \!META-c represents \!ESC followed by the letter c. The terminology is historical. Many commands accept an optional preceding count n, which is entered in decimal as META-digits, or as CTRL-U which multiplies the current count (initially 1) by 4. The command is executed that number of times.

Cursor Movement

n CTRL-B
n

Move the cursor back n characters.

n CTRL-F
n

Move the cursor forward n characters.

CTRL-A

Move the cursor to beginning of line.

CTRL-E

Move the cursor to end of line.

n META-b

Move the cursor back to nth previous beginning of word (string of alphanumerics).

n META-f

Move the cursor forward to nth beginning of word.

CTRL-]c

Move the cursor forward to next character c on current line.

META-space
CTRL-@

Set mark at cursor position.

CTRL-X CTRL-X

Exchange cursor position and mark.

Line Search

These commands display a different history line.
n CTRL-P
n

Select the nth previous command line from history.

n CTRL-N
n

Select the nth next command line from history.

META-<

Select the earliest command line from history.

META->

Select the latest command line from history.

n CTRL-R>string ENTER

Select the nth previous command line matching string. If n is zero, then select the next matching command after the current line.

Text Change

n erase (erase character)
n BACKSPACE
n CTRL-H

Delete n characters to the left of the cursor.

n CTRL-D

Delete n characters to the right of the cursor. If the current line is empty, then terminate the shell.

n META- CTRL-H
n META-h

Delete to the nth beginning of word before the cursor.

n META-d

Delete to the nth beginning of word after the cursor.

n CTRL-K

Delete from the cursor to the end of line. If n is zero, then delete from the beginning of line to the cursor.

kill (line kill character)
CTRL-G

Delete entire current line.

CTRL-W

Delete from cursor position to the mark (set with META-space or CTRL-@).

CTRL-T

In emacs mode, transpose the current character with the previous character and move the cursor forward. If the cursor is at the end of the line, or in gmacs mode, transpose the previous two characters.

CTRL-Y

Restore the last text deleted in emacs mode.

CTRL-C
CTRL-^

Capitalize character under cursor.

META-c

Capitalize word to right of cursor.

META-l

Lowercase word to right of cursor.

META-u

Uppercase word to right of cursor.

n META-.
n META-_

Insert the nth word of the previous command. If n is not given or it is zero, insert the last word of the previous command.

META-*

Replace the current word with the list of files which would match that word with a * appended.

META-ESC

Used to complete a path name. If there is only one existing path name that matches as much as you've typed, the path name is completed and a space is be added after the complete path name. If there are several matching path names, the shell expands what you've typed by adding all the characters that are common to all matching path names.

If the shell option tabcomplete is set (see set), hitting the <tab> key accomplishes the same thing.

META-=

Lists all path names matching the current word.

Miscellaneous

CTRL-J
CTRL-M
ENTER

Execute current command line.

CTRL-L

Re-display current command line.

CTRL-O

Remember the next command line, execute the current command line, then select the remembered line.

CTRL-U

Multiply the count on the following command by 4 (for each CTRL-U).

CTRL-U

Display the version of the shell.

\

Take the next character literally. Thus command and control characters can be entered in a command line or search string.

eof (end-of-file character)
CTRL-D

Terminate the shell.

META-n

Enter a count for the following command.


VI EDITING MODE

When the Vi editing facilities have been enabled by any of the means discussed in the first paragraph, the shell is initially in input mode after each new prompt. Keyboard input is normally inserted at the current position in the current command line; the exceptions are the following action keys.
Note:

In input mode, the cursor arrow keys are ignored.

erase (erase character)
BACKSPACE
CTRL-H

Delete the character to the left of the cursor.

eof (end-of-file character)
CTRL-D

Terminate the shell.

CTRL-W

Delete the word (white-space delimited string) to the left of the cursor.

kill (line kill character)
CTRL-X

Delete the current line.

CTRL-J
CTRL-M
ENTER

Execute the current line.

ESC

Switch from input mode to command mode (see below).

CTRL-V

Take the next character literally; useful for entering any of these action keys as text.

\

Escape the following action key. If the next character is any action key except CTRL-J, CTRL-M, or ENTER, the \ is erased and the escaped character is entered literally; otherwise the \ is entered, and the next character is treated normally.

If the ESC key is pressed, the shell enters command mode, and keyboard input is interpreted as commands to reposition the cursor, scroll through the command history, delete or change text, or re-enter input mode. In command mode input is not echoed; it is acted upon. Many commands take an optional count, n, which is entered as a preceding decimal number (not echoed); the command is executed that number of times. Except where otherwise noted, n defaults to 1. Commands are discussed in functional groups.

Cursor Movement

These commands reposition the cursor in the command line.
n h
n

Move back n characters.

n l

Move forward n characters.

0

(zero) -- Move to the first character on the line.

^

Move to the first non-blank character on the line.

$

Move to the last character on the line.

n w

Move to the beginning of the nth next word (string of alphanumerics, or of non-blank non-alphanumerics).

n W

Move to the beginning of the nth next full-word (string of non-blanks).

n b

Move to the nth previous beginning of word.

n B

Move to the nth previous beginning of full-word.

n e

Move to the nth next end of word.

n E

Move to the nth next end of full-word.

n fc

Move to the nth next character c.

n Fc

Move to the nth previous character c.

n tc

Move to the character before the nth next character c.

n Tc

Move to the character after the nth previous character c.

n ;

Repeat the previous f, F, t, or T command.

n ,

Repeat the previous f, F, t, or T command, but in the opposite direction.

%

Move to the balancing character if the cursor is positioned on one of the following characters:

(   )   {   }   [   ]   <   >
If the cursor is not positioned on one of these characters, the rest of the line is searched for the first occurrence of one of these characters and the cursor is then moved to its balancing character.

Line Search

The following change the current (displayed) command line.
n j
n +
n

Select the nth next command line from history.

n k
n -
n

Select the nth previous command line from history.

n G

Select the command with history number n, or the latest command if n is omitted.

n /string ENTER

Select the nth command line, searching backwards, which matches string. If string is omitted, the previous search string is used.

n ?string ENTER

Select the nth command line, searching forwards, which matches string. If string is omitted, the previous search string is used.

n n

Repeat the last string search (`/' or `?') command.

n N

Repeat the last string search, but in the opposite direction.

Text Change

The following commands alter the text in the current command line. Some of these commands operate on a text block, defined by an immediately following cursor movement command. This is designated by m (for movement) in the text change command. The text block extends from the current cursor position to the new position determined by the movement command.
i

Enter input mode, inserting text before the character under the cursor.

I

Insert before first non-blank on line (^i).

a

Move the cursor forward one character and enter input mode, appending text after the character originally under the cursor.

A

Append to end of line ($a).

n d m

Delete text block. If n is given, it is applied to the movement.

dd

Delete entire command line.

D

Delete from cursor to end of line (d$).

n x

Delete n characters to right of cursor (n dl).

n X

Delete n characters to left of cursor (n dh).

n c m

Change text block; deletes block of text and enters input mode. If n is given, it is applied to the movement.

cc
S

Change entire command line.

n s

Change next n characters from cursor.

n p

Put back, after the character under the cursor, n copies of the last block deleted by a text change command.

n P

Put back, before the character under the cursor, n copies of the last block deleted by a text change command.

r c

Replace the single character under the cursor with the character c, and advance the cursor one position.

R

Enter replace mode: a special case of input mode in which each character entered overwrites that under the cursor, and advances the cursor one position.

u

Undo the last text change to the current line. This is itself a text change command, and so acts as a toggle for the last change.

U

Undo all changes to the current line.

n ~

Invert the case of the next n characters, advancing the cursor over them.

n .

Repeat the last text change command. If n is given, it overrides the count originally given with the repeated command.

n _

Append after the character under the cursor, the nth argument from the previous command line (default last), and enter input mode.

*

Replace the current word with the list of file names that would match the word with a * appended. In the case of no match, the terminal beeps and the word is not changed; otherwise, the cursor is positioned at the end of the list and input mode is entered.

\

Used to complete a path name. If there is only one existing path name that matches as much as you've typed, the path name is completed and a spaces is added after the complete path name. If there are several matching path names, the shell expands what you've typed by adding all the characters that are common to all matching path names.

If the shell option tabcomplete is set (see set), hitting the <tab> key accomplishes the same thing.

=

Lists all path names matching the current word.

Miscellaneous

n y m

Yank text block into the delete buffer. Does not alter the command line or cursor position, but makes the text block available to subsequent put (p or P) commands. If n is given, it is applied to the movement.

yy

Yank entire command line.

Y

equivalent to y$ -- yank rest of line.

#

Equivalent to I#ENTER.

n v

Execute fc -e ${VISUAL:-${EDITOR:-vi}} n. If n is omitted, the history number of the current line is used.

CTRL-L

Re-display the current line.

CTRL-J
CTRL-M
ENTER

Execute the current line.


LIMITATIONS

Editor macros (one-letter aliases) are not implemented.

Selecting a previous history line for editing while at a secondary prompt (that is, while entering a subsequent line of a new multi-line command) yields bizarre results.


SEE ALSO

Commands:
fc, set, sh, vi


Updated MKS Toolkit [3khat16.ico]HP3000 [3khat16.ico]3kMail [archive16.gif]