Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

csh(1)

cmdedit(1)  —  Commands

NAME

cmdedit − C shell with command line editing

SYNOPSIS

/usr/bin/csh [ options ] [ args ... ]

DESCRIPTION

csh is a version of the C-shell with intra-command line editing.  Other features include a kill buffer, multi-line named keyboard macros which can be automatically saved and restored, convenient access to the history list, and user settable key bindings.  A summary of the currently available functions and their default key bindings is given in the BINDINGS section below.  In most cases the functionality will be apparent from the names of the routines in the list. 

The shell’s editing mode is determined by the value of the shell editmode variable which users should set to emacs or vi in their .cshrc files.  If editmode is not set, then the shell will run in "dumb" mode.  It is possible to set the mode after the shell starts up; so if you find yourself in "dumb" mode, you can alter the situation without having to logout and login again.  Setting the editmode variable has two important side effects:  (1) it causes the key bindings to be reevaluated, and (2) it sets the EDITMODE environment variable.  The latter has no effect within the shell; so users should not set the environment variable directly in hopes of altering the editing mode. 

Terminal control capabilities are extracted from the user’s termcap file (usually /etc/termcap), using the value of the shell variable term, not the environment variable TERM, as the terminal type.  If term is undefined, unknown, or if the associated termcap definition is inadequate, a warning will be displayed and most, or all, of the editing features of the shell will be disabled.  It is the user’s responsibility to make sure that term is set to an appropriate value before the shell editor is initialized.  Usually this should be done in the .login file.  If editing is disabled because term is not properly set when the shell starts up, simply setting term to the proper value will normally cause the shell editor to be re-enabled.  NB: Setting the shell variable term causes the environment variable TERM to be set to the same value.  For information on controlling the bell, see the ERRORS section. 

There is a bind-to-key command in this shell, which allows the functions listed in the BINDINGS section below, and also user defined keyboard macros, to be bound to keys.  The form of the command is

bind-to-key function key ...

where function is one of the function names from the list or else the single character name of a keyboard macro and where key is a quoted string designating a key sequence.  Control characters in the key designation should not be entered literally, but should be indicated by the prefix "\^", e.g. "\^X".  Similarly, escape is indicated by "\e".  A literal backslash is "\\". Escape and control-X are the only legitimate "prefix" characters.  For vi mode, bindings prefixed with control-X are for insert mode.  Otherwise, the bindings are only in effect in command mode. The following mnemonics should be used:

\^? delete (rubout)
\^c control character
\n line feed (new line)
\b back space
\t horizontal tab
\v vertical tab
\f form feed
\r carriage return
\e escape
\nnn character code in octal

Since the shell converts returns to newlines it is probably unwise to alter the binding of newline.  A common binding is to bind ­KillRegion to Ctrl/U, which would be accomplished using the following command:

bind-to-key KillRegion "\^U"

During editor initialization the shell will read a file named .bindings in the user’s home directory.  If you regularly want certain non-default key bindings to be effective, put the appropriate bind-to-key commands in your ~/.bindings file. 

NB: Do not place the bind-to-key commands in your ~/.cshrc or ~/.login file; they must be in the ~/.bindings file. 

Invocation of the history mechanism with "!" either causes the matched command to be inserted on the command line for editing before execution or immediatedly executes the command.  This is controlled by the shell variable edithist, which is automatically set, when the shell variable editmode is set, thereby allowing editing of previous commands invoked by the history mechanism.  This feature may be turned off with the command "unset edithist", which may be placed in the user’s .cshrc file. 

BINDINGS

The following functions and default key bindings are currently implemented. 

EmacsFunction NameRemark

^BBackspace
ESC−bBackwardWord
^ABeginningOfLine
^LClearScreen
DefaultBinding
ESC−nDefineNamedMacroname macro
^DDeleteCurrentChar
^HDeletePreviousChar
ESC−dDeleteWordafter cursor
EndOfFileexit shell
^EEndOfLine
EraseLinekills whole line
ESC−hEraseWordbefore cursor
ExecuteMacro
ESC−eExecuteNamedMacro
ESC−xExecuteNamedMacro
^X−eExecuteUnNamedMacro
ESC−ESCFilenameExpansion
ESC−lFilenameList
^FForwardChar
ESC−fForwardWord
GnuTransposeCharslike gnu-emacs
IncrementalSearchForward
IncrementalSearchReverse
InsertCharself insert
^VInsertLiteralChar
^WKillRegionto kill buffer
^KKillToEOLto kill buffer
^X^RLoadMacroFile
^NNextHistEntrywraps around
^PPreviousHistEntrywraps around
^RRedisplayredraws line
^URepetitiongreater than 0
^M,^JReturn
^X^SSaveMacroFile
^@SetMarkdefault mark at BOL
SearchReverselook for next char
SearchForwardlook for next char
^QStartFlow(see FLOW CONTROL)
^X−(StartRememberingbegin a macro
^SStopFlow(see FLOW CONTROL)
^X−)StopRememberingend a macro
^ITabinserts 8 spaces
^TTransposeCharsbefore cursor
WipeLinekill line without saving
^YYankKillBufferno kill ring
ViFunction NameRemark

AAppendToEOLcan’t use with
bind-to-key
^HBackSpace
hBackSpace
BBackwardWord
bBackwardWord
0BeginningOfLine
^BeginningOfLine
sChangeCharcan’t use with
bind-to-key
cChangeFollowingObjectcan’t use with
bind-to-key
CChangeToEOLcan’t use with
bind-to-key
SChangeWholeLinecan’t use with
bind-to-key
xDeleteCurrentChar
dDeleteFollowingObjectcan’t use with
bind-to-key
XDeletePreviousCharcan’t use with
bind-to-key
$EndOfLine
ESCFilenameExpansion
^DFilenameListOrEof
lForwardChar
SPACEForwardChar
wForwardWord
WForwardWord
eForwardWord
IInsertAtBOLcan’t use with
bind-to-key
DKillToEOL
@ExecuteNamedMacro
+NextHistEntry
jNextHistEntry
^NNextHistEntry
-PreviousHistEntry
kPreviousHistEntry
^PPreviousHistEntry
^LRedisplay
^RRedisplay
zRedisplay
1-9Repetition
rReplaceCharcan’t use with
bind-to-key
LINEFEEDReturn
RETURNReturn
/IncrementalSearchForward
?IncrementalSearchReverse
fSearchForward
FSearchReverse
mSetMark
aEnterViAppendcan’t use with
bind-to-key
iEnterViInsertcan’t use with
bind-to-key
pViYankKillBuffercan’t use with
bind-to-key
PViYankKillBuffercan’t use with
bind-to-key
Vi insert mode

^HDeletePreviousChar
EraseCharDeletePreviousChar
^WEraseWord
ESCExitViInsertcan’t use with
bind-to-key
^DFilenameListOrEof
^QInsertLiteralChar
^VInsertLiteralChar
^UKillRegion
^NNextHistEntry
^PPreviousHistEntry
^LRedisplay
^RRedisplay
LINEFEEDReturn
RETURNReturn
TABTab

Users may change the bindings of functions to keys by means of the shell bind-to-key command.  These commands may be stored in a file named .bindings in the user’s home directory and will then be read by the shell when the editor is initialized. 

FLOW CONTROL

Flow control is handled by the terminal driver, not by the shell.  The terminal driver normally interprets ^S and ^Q as a signal to respectively stop and restart output to the terminal.  By default, the shell does not override these "bindings", but the user may override them by rebinding ^S or ^Q to functions other than StopFlow and StartFlow. 

The functions StopFlow and StartFlow can only be usefully bound to the keys that the terminal driver interprets as performing the corresponding flow control functions.  In other words, you cannot simply bind these functions to other keys in order to have them perform the flow control operations normally provided by ^S and ^Q. 

KEYBOARD MACROS

Keyboard macros can be used to simplify repetitive operations and reduce typing lengthy commands.  For example, the following lines illustrate how to create a macro to startup Emacs and have it run the shell inside a buffer:

% ^X(emacs -eshell
% ^X)

Notice that this is a multi-line macro, since it contains an embedded newline.  The user can give this macro a single character name, e.g. "e", as follows:

% \ene   (escape-n-e).

The macro may then be executed by typing "\exe".  It can also be bound to a key using the bind-to-key command.  Macros can be saved in files and can be reloaded automatically when the shell starts up. 

Macro Creation
To create a new unnamed macro, use the StartRemembering function which is bound by default to ^X(.  Subsequent keystrokes, until the StopRemembering, ^X ), function is executed, are remembered as an "unnamed" keyboard macro.  It can contain at most 1024 characters.  You are not allowed to begin creating another macro during macro creation, but it is okay to execute other macros, provided loops aren’t created.  The unnamed macro can be executed using the ExecuteUnNamedMacro function, bound to ^Xe.  There is only one unnamed macro. 

Named Macros
Users can have up to 128 named macros.  To define such a macro, first create an unnamed macro as above and then give it a name by executing the DefineNamedMacro function, bound to \en (escape-n).  The function takes a single character argument which will be the name of the macro.  Any previous macro with that same name will be destroyed. 

Macro Execution
To execute a named macro simply use the ExecuteNamedMacro function, bound to \ex, and give it the name of the macro to be executed.  Named macros can also be bound to keys using the builtin cshell command bind-to-key. 

Macro Files
Named keyboard macros can be saved in files and loaded from files.  To save the named macros in a file simply type the filename on the command line (by itself) and then execute the SaveMacroFile function bound to ^X^S.  To read a file of previously saved macros type the filename on the command line and execute the LoadMacroFile function bound to ^X^R.  Success in each case is indicated by the erasure of the filename.  It is okay to store macros in several different macro files.  NB:  It is not advisable to try to edit saved macros! 

Autoloading and AutoSaving Macros
If the shell variable macrofiles is assigned (in the user’s .cshrc file) the names of one or more files of saved keyboard macros, then those macro files will be automatically loaded when the shell starts up.  Similarly, the variable savemacros can be assigned the name of a (single) file in which all named macros will be saved when the user logs out. 

SEARCHING

NB: The names of the incremental search functions have changed since earlier releases of this shell. 

Four search functions are available to the user, but are not bound (by default) to keys.  If you want to use them, use the cshell bind-to-key command to bind them to keys. 

IncrementalSearchForward
When the user executes this function he is placed in a read/search loop in which the string to be found is built up character by character.  As each new character is added to the search string the cursor is placed at the end of the first match on the command line following the position of the cursor when the function was executed.  You can reexecute the search function while in the loop to cause the cursor to move to subsequent matches.  Type ESC to exit the loop.

IncrementalSearchReverse
This function is similar to IncrementalSearchForward except that the cursor is placed at the beginning of the first match on the command line preceding the position of the cursor when the function was executed.

SearchForward
This function grabs the next character you type and searches for that character from the position of the cursor to the end of the command line, leaving the cursor following the first instance of the character if one is found.

SearchReverse
This function is like SearchForward except that it searches from where the cursor is to the beginning of the command line.

MISCELLANEOUS

If the shell variable breakchars is assigned a string, then the characters in that string are used to determine word boundaries.  The default break characters are " ", ",", ^I, /, \, (, ), [, ], {, }, ., ;, >, <, !, ^, &, and |.  The user defined break characters are used instead of, not in addition to, the default list. 

RESTRICTIONS

The display update functions take no advantage of the capabilities of smart terminals.  This will be fixed in the future. 

The command line cannot exceed 1024 characters if characters are being inserted in the middle of the line; it can be longer if characters are being inserted at the end, but once the 1K boundary is passed the previous characters can no longer be edited or redisplayed. 

The interactive input routine performs some initialization the first time it is called.  As a result some things are not interactively alterable.  It is also not possible for the user to turn off echoing of regular characters or to take the tty out of CBREAK mode by means of the stty command, for example, and have it affect the function of the shell. 

ERRORS

Error conditions within the editor functions are usually indicated by an audible bell.  If you prefer a visual signal and your terminal has a visible bell capability, then you should set the variable visiblebell in your .cshrc file.  If you want an audible bell also, then set both visiblebell and audiblebell.  If you don’t want to be told about your mistakes, you can set the nobell variable. 

RELATED INFORMATION

Commands: csh(1)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026