5.5   Shell Line Editing

The WindSh front end provides a history mechanism similar to the UNIX Korn-shell history facility, including a built-in vi-like line editor that allows you to scroll, search, and edit previously typed commands. Line editing is available regardless of which interpreter you are using (C or Tcl1 ), and the command history spans both interpreters--you can switch from one to the other and back, and scroll through the history of both modes.

You can control what characters to use for certain editing commands. The input keystrokes shown in Table 5-14 (5.3.13 Terminal Control Characters) are set by the host stty command (which you can call from the Tcl interpreter; see 5.7 Tcl: Shell Interpretation). They must be single characters, usually control characters; Table 5-15 includes these characters, but shows only common default values.

The ESC key switches the shell from normal input mode to edit mode. The history and editing commands in Table 5-15 are available in edit mode.

Some line-editing commands switch the line editor to insert mode until an ESC is typed (as in vi) or until an ENTER gives the line to one of the shell interpreters. ENTER always gives the line as input to the current shell interpreter, from either input or edit mode.

In input mode, the shell history command h( ) (described in System Information) displays up to 20 of the most recent commands typed to the shell; older commands are lost as new ones are entered. You can change the number of commands kept in history by running h( ) with a numeric argument. To locate a line entered previously, press ESC followed by one of the search commands listed in Table 5-15; you can then edit and execute the line with one of the commands from Table 5-15.


*

NOTE: Not all the editing commands that take counts in vi do so in the shell's line editor. For example, ni does not repeat the inserted text n times.

Table 5-15:  Shell Line-Editing Commands


Basic Control
 
h [size]
   
Display shell history if no argument; otherwise set history buffer to size.
 
ESC
   
Switch to line-editing mode from regular input mode.
 
ENTER
   
Give line to shell and leave edit mode.
 
CTRL+D
   
Complete symbol or path name (edit mode), display synopsis of current symbol (symbol must be complete, followed by a space), or end shell session (if the command line is empty).
 
[tab]
   
Complete symbol or path name (edit mode).
 
CTRL+H
   
Delete a character (backspace).
 
CTRL+U
   
Delete entire line (edit mode).
 
CTRL+L
   
Redraw line (works in edit mode).
 
CTRL+S and CTRL+Q
 
Suspend output, and resume output.
 
CTRL+W
   
Display HTML reference page for a routine.
 
Movement and Search Commands
 
nG
   
Go to command number n.1
 
/s or ?s
   
Search for string s backward in history, or forward.
 
n
   
Repeat last search.
 
nk or n-
   
Get nth previous shell command.*
 
nj or n+
   
Get nth next shell command.*
 
nh
   
Go left n characters (also CTRL+H).*
 
nl or SPACE
   
Go right n characters.*
 
nw or nW
   
Go n words forward, or n large words. *2
 
ne or nE
   
Go to end of the nth next word, or nth next large word. *
 
nb or nB
   
Go back n words, or n large words.*
 
$
   
Go to end of line.
 
0 or ^
   
Go to beginning of line, or first nonblank character.
 
fc or Fc
   
Find character c, searching forward, or backward.
 
Insert and Change Commands
 
a or A
 
...ESC
 
Append, or append at end of line (ESC ends input).
 
i or I
 
...ESC
 
Insert, or insert at beginning of line (ESC ends input).
 
ns
 
...ESC
 
Change n characters (ESC ends input).*
 
nc SPACE
 
...ESC
 
Change n characters (ESC ends input).*
 
cw
 
...ESC
 
Change word (ESC ends input).
 
cc or S
 
...ESC
 
Change entire line (ESC ends input).
 
c$ or C
 
...ESC
 
Change from cursor to end of line (ESC ends input).
 
c0
 
...ESC
 
Change from cursor to beginning of line (ESC ends input).
 
R
 
...ESC
 
Type over characters (ESC ends input).
 
nrc
   
Replace the following n characters with c.*
 
~
   
Toggle case, lower to upper or vice versa.
 
Delete Commands
 
nx
   
Delete n characters starting at cursor.*
 
nX
   
Delete n character to left of cursor.*
 
dw
   
Delete word.
 
dd
   
Delete entire line (also CTRL+U).
 
d$ or D
   
Delete from cursor to end of line.
 
d0
   
Delete from cursor to beginning of line.
 
Put and Undo Commands
 
p or P
   
Put last deletion after cursor, or in front of cursor.
 
u
   
Undo last command.
 

1:  The default value for n is 1.

2:  words are separated by blanks or punctuation; large words are separated by blanks only.


1:  The WindSh Tcl-interpreter interface is described in 5.7 Tcl: Shell Interpretation.