For Users

This page is for the user of a Reline application.

In Brief

This section is a quick reference for the Reline commands; details at the links.

Moving the Cursor

Changing Text

Undoing and Redoing

Killing and Yanking

Manipulating History

Completing Words

Reline Application

A Reline application is a Ruby console application that uses module Reline.

Such an application typically implements a REPL (Read-Evaluate-Print Loop) that allows you to type a command, get a response, type another command, get another response, and so on.

A Reline application by default supports:

A Reline application may support:

Reline in Ruby

Ruby itself includes these Reline applications:

Reline Defaults

Note that this page describes the default usages for Reline, with both command history and word completion enabled, as in this simple “echo” program:

require 'reline'

puts 'Welcome to the Echo program!'
puts '  To exit, type Ctrl-d in empty line.'

# Words for completion.
Words = %w[ foo_foo foo_bar foo_baz qux ]
Reline.completion_proc = proc { |word| Words }

# REPL (Read-Evaluate-Print Loop).
while line = Reline.readline(prompt = 'echo> ', history = true)
  puts "You typed: '#{line.chomp}'."
end

Other console applications that use module Reline may have implemented different usages.

About the Examples

Examples on this page are derived from the echo program above.

Notations

Reline is basically a domain-specific language, implemented via certain keys, control characters, and meta characters.

To denote these here in the documentation, we use certain notations.

Keys

Arrow keys:

Other keys:

Control Characters

C-k (pronounced “Control-k”) denotes the input produced when Ctrl is depressed (held down), then the k key is then pressed, and both are released.

Almost any character can have a “control” version: C-a, C-{, C-], etc.

Meta Characters

M-k (pronounced “Meta-k”) denotes the input produced when the Alt is depressed (held down), then the k key is then pressed, and both are released.

Almost any character can have “meta” version: M-c, M->, M-#, etc.

An alternative to using the Alt key is the Escape key: press the Escape key before the character key.

Repetition

A command may be prefixed by an integer argument that specifies the number of times the command is to be executed.

Some commands support repetition; others do not. See individual commands.

If repetition for the command is supported and a repetition value of n is given, the command is executed n times.

It the repetition for the command is not supported, the repetition prefix is ignored.

Undo and Redo

The undo command (C-_) “undoes” the action of a previous command (if any) on the current command line.

The redo command(M-_) “redoes” the action of a previous undo on the current command line.

Nothing is ever undone or redone in an already-entered line.

In general, an “undoable” or “redoable” command is one that moved the cursor or modified text. Other commands are not undoable or redoable, but instead “pass through” the command to earlier commands; see below.

Immediate Undo and Redo

When the undo command is given and the immediately preceding command is undoable, that preceding command is undone.

When the redo command is given and the immediately preceding undo is redoable, that preceding command is redone.

“Pass-Through” Undo and Redo

When the undo command is given and the immediately preceding command is not undoable, the undo command “passes through” to commands given earlier. Reline searches backward through the most recent commands for the current line:

When the redo command is given and the immediately preceding undo is not redoable, the redo command “passes through” to commands given earlier. Reline searches backward through the most recent commands for the current line:

Command-Line Editing

Killing and Yanking

Killing means deleting text from the current line and saving it in a kill buffer for potential later use (by yanking).

Yanking means inserting previously-killed text into the current line. Yanked text is copied from the kill buffer.

Killed text is put onto the kill buffer:

The kill buffer is not associated with a particular command line; text killed from a the current line is available for yanking into later command lines.

Word Completion

A Reline application may support command word completion, which is implemented via the Tab command.

The example echo program has loaded a collection of words that it uses for completing words:

Words = %w[ foo_foo foo_bar foo_baz qux ]

In the echo program, typing 'f' followed by Tab lets the program do a partial word completion, adding 'oo_' to form 'foo_'.

The program can add the partial completion 'oo_' because all the available words that begin with 'f' also begin with 'foo_'.

But it can’t complete the word because there are multiple words that begin with 'foo_'.

If we add 'b' and Tab, the program can add 'bar' to form the complete word 'foo_bar', because that’s the only word that begins 'foo_b'.

To see the completion possibilities, type Tab twice; this example types f followed by two Tabs:

echo> foo_
foo_bar  foo_baz  foo_foo

Word completion works on the current word in the line, which may not be the only word; this example types 'xyzzy f' followed by two Tabs to get the possible completions:

echo> xyzzy foo_
foo_bar  foo_baz  foo_foo

Command History

A Reline application may support command history.

An easy way to find out whether it does: after entering one or more commands, press key :

Traversing History

Use any number of C-p or commands to move upward in the command history; the first such command displays the most recent command, the second, the next-most-recent command, and so forth.

When in the history, use any number of C-n or commands to move downward in the command history.

At any time, if the displayed command is exactly the one you want to execute, press Enter.

Otherwise, You can edit the displayed command using the various Reline editing tools (including Undo), then Enter it when satisfied.

Searching History

Use command C-r to search upward in the history.

When you give that command, Reline displays this:

(reverse-i-search)`':

The command is interactive in the sense that if you type a, Reline displays the first found command that matches the a.

At that point you can:

Exiting the Application

To exit the application, use command C-d on an empty command line.

Command Line Commands

Commands for Moving the Cursor

C-f or : Character Forward

C-b or : Character Backward

M-f: Word Forward

M-b: Word Backward

C-a: Beginning of Line

C-e: End of Line

C-l: Clear Screen

M-C-l: Clear Display

Commands for Changing Text

Any Printable Character: Insert Character

Delete: Delete Character Forward

C-d: Delete Character Forward (Non-Empty Line)

Like Delete if line non-empty; otherwise, exit the application.

Backspace: Delete Character Backward

C-t: Transpose Characters

M-t: Transpose Words

M-u: Upcase Word

M-l: Downcase Word

M-c: Capitalize Word

Commands for Undoing and Redoing

Undo Previous Command

Redo Previous Undo

Commands for Killing and Yanking

C-k: Kill Line Forward

C-u: Kill Line Backward

M-d: Kill Word Forward

C-w: Kill Word Backward

C-y: Yank Last Kill

Commands for Manipulating the History

Enter: Accept Line

C-p or : Previous History

C-n or : Next History

C-r: Reverse Search

Commands for Completing Words

Tab: Complete Word

Tab Tab: Show Completions