Simple Line Editing Commands

A variety of command line oriented programs allow you to edit the commands before executing them. While the commands differ, Windows users will recognize the spirit as being that of the MS-DOS command shell. Among these programs are the command line versions of Maple and MATLAB, the SAGE and Python languages, and the UNIX Bash and Korn shells. While some of these allow a choice of command sets, we will discuss the "emacs-like" command sets which are (almost) common among these programs.

Editing with Arrows

The simplest approach to editing is to see which of the keyboard's movement keys are recognized. These keys are:

A given pair of program at the far end and terminal program at your end may or may not support any of these keys. If one of the keys is not recognized (and if you have time to burn) you can check the "preferences" or "configuration" of your terminal program. A simpler solution may be to use the emacs commands listed in the next section.

Editing with Emacs Commands


Although they are by no means as self-explanatory as the use of arrows, the subset of emacs commands are more likely to work with a given terminal program, as well as providing a richer set of functions. Most of these commands are of the form control-letter (written ^letter), where you hold down the control key while typing the letter key. The simplest commands (those which directly replace the keys from the preceding section) are:

Cut & Paste

The easiest way to copy expressions from one command to another is to use your own computer's clipboard, together with the terminal program's Cut and Paste menu commands. If this is not practical, or if you are in the mood to do everything with a command key, the emacs edit keys include their own cut and paste function.

This also allows you to cut and paste a number of contiguous lines. If the lines are killed without any intervening commands, they will all be in the kill ring and can all be recalled with a single ^y (yank) command.

The History Buffer

Some programs keep a history of commands which have been executed. Commands in this buffer can be recalled in a variety of ways. Some programs have special symbols to recall them (!! in UNIX's C Shell, % in Mathematica and Maple).

A simpler approach which is now commonly used is to view them as being written in a file (the history buffer), so that you can go to earlier commands by going "up" in the file with the up arrow key or the "^p" command. Using this approach you can scroll back through earlier commands until you find the one you want, and then edit it to create a new command.

Commands which can be used to scroll or search within the history buffer include:

Mechanics: How it Works

The ability to edit and recall commands from within a command line program is generally implemented by one of a small number of libraries, most notably the GNU readline library and its workalike, the editline library. (Editline, also called libedit, differs from readline primarily in being offered under the BSD license, which is less restrictive of commercial use than the GNU license which readline is offered under.

Robert Campbell
28 December, 2000