ArticleslgStudy

computer science

GNU Readline

GNU Readline is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand GNU Readline rather than just read about it. In short: GNU Readline is a software library that provides in-line editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project.

GNU Readline — main illustration
GNU Readline — illustration

Key takeaways

  • GNU Readline belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect GNU Readline to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of GNU Readline from memory before moving on to harder problems.

Reference excerpt

GNU Readline is a software library that provides in-line editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project. It allows users to move the text cursor, search the command history, control a kill ring (a more flexible version of a copy/paste clipboard) and use tab completion on a text terminal. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.

History Readline was created in 1988 by Free Software Foundation employee Brian Fox to implement line editing functionality required by POSIX for its shell. After the release of version 1.05, Fox passed control to Chet Ramey of Case Western who has been the sole maintainer since 1998.

Editing modes Readline supports both Emacs and vi editing modes, which determine how keyboard input is interpreted as editor commands. POSIX prescribes the vi editing mode while leaving other editing modes unspecified and in the discretion of implementations. Readline originally included its Emacs editing mode due to the influence of Korn Shell's Emacs editing mode. Emacs is the default mode.

Emacs keyboard shortcuts Emacs editing mode key bindings are taken from the text editor Emacs. On some systems, Esc must be used instead of Alt, because the Alt shortcut conflicts with another shortcut. For example, pressing Alt+f in Xfce's terminal emulator window does not move the cursor forward one word, but activates "File" in the menu of the terminal window, unless that is disabled in the emulator's settings.

Tab ↹ : Autocompletes from the cursor position. Ctrl+a : Moves the cursor to the line start (equivalent to the key Home). Ctrl+b : Moves the cursor back one character (equivalent to the key ←). Ctrl+c : Sends the signal SIGINT via pseudoterminal to the current task, which aborts and closes it. Ctrl+d Sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command exit). (Only if there is no text on the current line) If there is text on the current line, deletes the current character (then equivalent to the key Delete). Ctrl+e : (end) moves the cursor to the line end (equivalent to the key End). Ctrl+f : Moves the cursor forward one character (equivalent to the key →). Ctrl+g : Abort the reverse search and restore the original line. Ctrl+h : Deletes the previous character (same as backspace). Ctrl+i : Equivalent to the tab key. Ctrl+j : Equivalent to the enter key. Ctrl+k : Clears the line content after the cursor and copies it into the clipboard. Ctrl+l : Clears the screen content (equivalent to the command clear). Ctrl+n : (next) recalls the next command (equivalent to the key ↓). Ctrl+o : Executes the found command from history, and fetch the next line from the history for editing. Ctrl+p : (previous) recalls the prior command (equivalent to the key ↑). Ctrl+r : (reverse search) recalls the last command including the specified characters. A second Ctrl+r recalls the next anterior command that corresponds to the search. Ctrl+s : Go back to the next more recent command of the reverse search (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use Ctrl+q to return. Ctrl+t : Transpose the previous two characters. Ctrl+u : Clears the line content before the cursor and copies it into the clipboard. Ctrl+v : If the next input is also a control sequence, type it literally (e. g. * Ctrl+v Ctrl+h types "^H", a literal backspace). Ctrl+w : Clears the word before the cursor and copies it into the clipboard. Ctrl+x Ctrl+e : Edits the current line in the $EDITOR program, or vi if undefined. Ctrl+x Ctrl+r : Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there. Ctrl+x Ctrl+u : Incremental undo, separately remembered for each line. Ctrl+x Ctrl+v : Display version information about the current instance of Bash. Ctrl+x Ctrl+x : Alternates the cursor with its old position. (C-x, because x has a crossing shape). Ctrl+y : (yank) adds the clipboard content from the cursor position. Ctrl+z : Sends the signal SIGTSTP to the current task, which suspends it. To execute it in background one can enter bg. To bring it back from background or suspension fg ['process name or job id'] (foreground) can be issued. Ctrl+_ : Incremental undo, separately remembered for each line. Alt+b : (backward) moves the cursor backward one word. Alt+c : Capitalizes the character under the cursor and moves to the end of the word. Alt+d : Cuts the word after the cursor. Alt+f : (forward) moves the cursor forward one word. Alt+l : Lowers the case of every character from the cursor's position to the end of the current word. Alt+r : Cancels the changes and puts back the line as it was in the history. Alt+u : Capitalizes every character from the cursor's position to the end of the current word. Alt+. : Insert the last argument to the previous command (the last word of the previous history entry).

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with GNU Readline

Start with the simplest possible case. Write down what GNU Readline claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to GNU Readline before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about GNU Readline ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of GNU Readline

In research
GNU Readline appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses GNU Readline in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
GNU Readline is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free software programmed in C, GNU Project software, Software using the GNU General Public License, so understanding it makes those chapters shorter.
In everyday life
Look for GNU Readline outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “GNU Readline” →

How to study GNU Readline in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what GNU Readline means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain GNU Readline out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is GNU Readline in simple terms?

GNU Readline is a software library that provides in-line editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project.

Why does GNU Readline matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study GNU Readline?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on GNU Readline.

Tags

  • Free software programmed in C
  • GNU Project software
  • Software using the GNU General Public License
  • Termcap
  • Text user interface libraries

Keep exploring