2.4 Command-line editing ¶
Gforth maintains a history file that records every line that you type to
the text interpreter. This file is preserved between sessions, and is
used to provide a command-line recall facility; if you type Ctrl-P
repeatedly you can recall successively older commands from this (or
previous) session(s). The full list of command-line editing facilities is:
- Ctrl-p (“previous”) (or up-arrow) to recall successively older
lines from the history buffer.
- Ctrl-n (“next”) (or down-arrow) to recall successively newer
lines from the history buffer. If you moved to an older line earlier
and gave it to Gforth for text-interpretation, asking for the next
line as the first editing command gives you the next line after the
one you selected last time.
- Ctrl-f (or right-arrow) to move the cursor right, non-destructively.
- Ctrl-b (or left-arrow) to move the cursor left, non-destructively.
- Ctrl-h (backspace) to delete the character to the left of the cursor,
closing up the line.
- Ctrl-k to delete (“kill”) from the cursor to the end of the line.
- Ctrl-a to move the cursor to the start of the line.
- Ctrl-e to move the cursor to the end of the line.
- RET (Ctrl-m) or LFD (Ctrl-j) to submit the current
line.
- TAB to step through all possible full-word completions of the word
currently being typed.
- Ctrl-d on an empty line line to terminate Gforth (gracefully,
using
bye
).
- Ctrl-x (or
Ctrl-d
on a non-empty line) to delete the
character under the cursor.
When editing, displayable characters are inserted to the left of the
cursor position; the line is always in “insert” (as opposed to
“overstrike”) mode.
On Unix systems, the history file is
$HOME/.local/share/gforth/history by default. You can find out the name
and location of your history file using:
history-file type \ Unix-class systems
history-file type \ Other systems
history-dir type
If you enter long definitions by hand, you can use a text editor to
paste them out of the history file into a Forth source file for reuse at
a later time.
Gforth never trims the size of the history file, so you should do this
periodically, if necessary.