sheditinteractive command and history editing in the KornShell |
Miscellaneous Information |
set
-o
editmode
EDITOR=
editprog
VISUAL=
editprog
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.)
These facilities are also enabled (with the corresponding option set) by assigning a value ending inset -o emacs set -o gmacs set -o vi
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
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.
CTRL-B
Move the cursor back n characters.
CTRL-F
Move the cursor forward n characters.
CTRL-A
Move the cursor to beginning of line.
CTRL-E
Move the cursor to end of line.
META-b
Move the cursor back to nth previous beginning of word (string of alphanumerics).
META-f
Move the cursor forward to nth beginning of word.
CTRL-]
cMove the cursor forward to next character c on current line.
META-
spaceCTRL-@
Set mark at cursor position.
CTRL-X CTRL-X
Exchange cursor position and mark.
CTRL-P
Select the nth previous command line from history.
CTRL-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.
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.
BACKSPACE
CTRL-H
Delete n characters to the left of the cursor.
CTRL-D
Delete n characters to the right of the cursor. If the current line is empty, then terminate the shell.
META- CTRL-H
META-h
Delete to the nth beginning of word before the cursor.
META-d
Delete to the nth beginning of word after the cursor.
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.
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.
META-.
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 optiontabcomplete
is set (see
set
),
hitting the <tab> key accomplishes the same thing.META-=
Lists all path names matching the current word.
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.
CTRL-D
Terminate the shell.
META-
nEnter a count for the following command.
In input mode, the cursor arrow keys are ignored.
BACKSPACE
CTRL-H
Delete the character to the left of the cursor.
CTRL-D
Terminate the shell.
CTRL-W
Delete the word (white-space delimited string) to the left of the cursor.
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.
1
. Commands are discussed in
functional groups.
h
Move back n characters.
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.
w
Move to the beginning of the nth next word (string of alphanumerics, or of non-blank non-alphanumerics).
W
Move to the beginning of the nth next full-word (string of non-blanks).
b
Move to the nth previous beginning of word.
B
Move to the nth previous beginning of full-word.
e
Move to the nth next end of word.
E
Move to the nth next end of full-word.
f
cMove to the nth next character c.
F
cMove to the nth previous character c.
t
cMove to the character before the nth next character c.
T
cMove to the character after the nth previous character c.
;
Repeat the previous f
, F
,
t
, or T
command.
,
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.( ) { } [ ] < >
j
+
Select the nth next command line from history.
k
-
Select the nth previous command line from history.
G
Select the command with history number n, or the latest command if n is omitted.
/
string ENTER
Select the nth command line, searching backwards, which matches string. If string is omitted, the previous search string is used.
?
string ENTER
Select the nth command line, searching forwards, which matches string. If string is omitted, the previous search string is used.
n
Repeat the last string search (`/
' or
`?
') command.
N
Repeat the last string search, but in the opposite direction.
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
).
d
mDelete 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$
).
x
Delete n characters to right of cursor
(n dl
).
X
Delete n characters to left of cursor
(n dh
).
c
mChange 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.
s
Change next n characters from cursor.
p
Put back, after the character under the cursor, n copies of the last block deleted by a text change command.
P
Put back, before the character under the cursor, n copies of the last block deleted by a text change command.
r
cReplace 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.
~
Invert the case of the next n characters, advancing the cursor over them.
.
Repeat the last text change command. If n is given, it overrides the count originally given with the repeated command.
_
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 optiontabcomplete
is set (see
set
),
hitting the <tab> key accomplishes the same thing.=
Lists all path names matching the current word.
y
mYank 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
.
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.