Next Previous Contents

3. Using Readline

This command uses the GNU Readline Library. This allows you to edit the commands you've entered as if you were using a text editor. You can move the cursor, insert or delete text, and much more. If you are familiar with Readline, you probably want to skip this section. This is because the Readline library provides a consistent user interface between all programs that use it.

3.1 Readline essentials

You can enter characters as usual. Just type them, and they'll appear on the screen. Use the Backspace key (or the Delete key, if your keyboard doesn't have a Backspace key) to delete the last character. To move the cursor, use the left and right arrow keys. If your keyboard doesn't have arrow keys, the keys Control-b and Control-f will move the cursor to the left and right, respectively. To move forward or backward a word, use the Alt-b and Alt-f keys. The "Alt" key may be labelled "Edit" on some keyboards. If you don't have an Alt or Edit key, press ESC, release it and then press b (or f). This combination works for all commands that use the Alt key.

To move to the beginning of the line, use Control-a. To move to the end of the line, use Control-e.

Another useful command is Control-_ (underscore). It undoes the last action. So, if you make a mistake, just press Control-_ to undo it.

3.2 Killing text

Killing means deleting text from a line, but saving it somewhere it can be later brought again. The operation of bringing back killed text is called "yanking".

Whenever you use one of the kill commands, the text is saved in the "kill ring". Any number of consecutive kills saves the text together, so when you yank it you'll get it all back. The kill-ring is not line-specific, you may yank text from a previous line.

The most frequently used kill and yank commands are:

Control-k

Kill text from the cursor position to the end of the line.

Alt-d

Kill from the cursor postion to the end of the current word, or, if between words, to the end of the next word.

Alt-Backspace (or Alt-Del in some computers)

Kill from the cursor postion to the start of the current word, or, if between words, to the start of the previous word.

Control-y

Yank the most recently killed text back at the cursor position.

Alt-y

Rotate the kill-ring. This command can only be used if the previous command was Control-y or Alt-y. This replaces the last yanked text with the text that was killed before it.

3.3 Numeric Arguments

Most Readline commands support numeric arguments. For example, if you give the argument 5 to the command Control-f (go forward a character) it goes five characters forward.

To enter an argument to a command, press Alt and the argument digit simultaneously. For example, to give the Control-f command an argument of 10, press Alt-1 0 Control-f. Arguments can also be negative, if you press Alt-- (hyphen) as the first argument digit. If you just specify "-" as argument, it is equivalent to -1.

3.4 The history

All commands you type are saved in the history. To cycle through the commands in the history in order, use the up and down arrow keys or the Control-p and Control-n keys.

To search the history for a specific entry, press Control-R then enter part of the command. As your entry matches the history lines, they are shown. When you've found what you wanted, press Enter to execute the command or any other key to execute the action bound to that key. To finish a search, use Control-g.

3.5 Other commands

In calc use the Tab key to insert the element in level one at the command line. With an argument, inserts the number at the given level.

There are also many other commands for Readline, and it can also be customized for your personal taste. For more information, see the Readline manual.


Next Previous Contents