Files
hpr_website/www/eps/hpr2073/hpr2073_full_shownotes.html

115 lines
6.2 KiB
HTML
Raw Permalink Normal View History

2025-10-28 18:39:57 +01:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Dave Morriss">
<title>The power of GNU Readline - part 1 (HPR Show 2073)</title>
<style type="text/css">code{white-space: pre;}</style>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="http://hackerpublicradio.org/css/hpr.css">
</head>
<body id="home">
<div id="container" class="shadow">
<header>
<h1 class="title">The power of GNU Readline - part 1 (HPR Show 2073)</h1>
<h2 class="author">Dave Morriss</h2>
<hr/>
</header>
<main id="maincontent">
<article>
<header>
<h1>Table of Contents</h1>
<nav id="TOC">
<ul>
<li><a href="#gnu-readline">GNU Readline</a></li>
<li><a href="#keys-and-notation">Keys and Notation</a></li>
<li><a href="#commands-you-probably-already-know">Commands you probably already know</a></li>
<li><a href="#commands-you-might-not-know">Commands you might not know</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#links">Links</a></li>
</ul>
</nav>
</header>
<h2 id="gnu-readline">GNU Readline</h2>
<p>We all use <em>GNU Readline</em> if we we use the CLI in Linux because it manages input, line editing and command history in Bash and in many tools.</p>
<p>I have been using Unix and later Linux since the 1980's, and gradually learnt how to do things like jump to the start or the end of the line, delete a character backwards up to a space, or delete the entire line.</p>
<p>I think that learning GNU Readline is worthwhile since it contains a <strong>lot</strong> more features than what I just described. I thought I would do a few episodes on HPR to introduce some of what I consider to be the most useful features.</p>
<p>I want to keep the episodes short since this is a dry subject, and, if you are anything like me, you can't take in more than a few key sequences at a time.</p>
<p>The source of my information is the <a href="http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html" title="GNU Readline Manual"><em>GNU Readline Manual</em></a>. This is very well written, if a little overwhelming.</p>
<h2 id="keys-and-notation">Keys and Notation</h2>
<p>Most of the features in GNU Readline are invoked by multi-key sequences. These involve the <code>Control</code> key and the so-called <code>Meta</code> key. The <code>Control</code> key is usually marked <strong>Ctrl</strong> on the keyboard. The <code>Meta</code> key is the key marked <strong>Alt</strong>.</p>
<p>The notation used in the GNU Readline manual is <code>C-k</code> for '<em>Control-k</em>', meaning the character produced when the <code>k</code> key is pressed while the <code>Control</code> key is being held down.</p>
<p>For the <code>Meta</code> key the notation <code>M-k</code> (<strong>Meta-k</strong>) means the character produced when the <code>k</code> key is pressed while the <code>Meta</code> key is being held down.</p>
<p>If your keyboard does not have a <code>Meta</code> key then the same result can be obtained by pressing the <code>Esc</code> key, releasing it, then pressing the <code>k</code> key.</p>
<p>In some instances both the <code>Control</code> and the <code>Meta</code> key might be used, so <code>M-C-k</code> would mean the character produced when the <code>k</code> key is pressed while the <code>Meta</code> and <code>Control</code> keys are being held down.</p>
<h2 id="commands-you-probably-already-know">Commands you probably already know</h2>
<dl>
<dt><code>C-b</code></dt>
<dd>Move back one character. This is the same as the left arrow key if you have one.
</dd>
<dt><code>C-f</code></dt>
<dd>Move forward one character. This is the same as the right arrow key if you have one.
</dd>
<dt><code>Backspace</code></dt>
<dd>Delete the character to the left of the cursor.
</dd>
<dt><code>C-d</code></dt>
<dd>Delete the character underneath the cursor.
</dd>
<dt><code>DEL</code></dt>
<dd><strong>Depends on your setup</strong> may be the same as <code>Backspace</code> or <code>C-d</code>. In my case (Debian Testing with Xfce) it's the same as <code>C-d</code>.
</dd>
</dl>
<h2 id="commands-you-might-not-know">Commands you might not know</h2>
<dl>
<dt><code>C-_</code> (or <code>C-x</code> <code>C-u</code>)</dt>
<dd>Undo the last editing command. Can undo all the way back to the blank line you started with. Remember the '_' underscore is usually on the same key as the '-' hyphen, so you'll need to use <code>Control</code>, <code>Shift</code> and underscore.
</dd>
<dt><code>C-a</code></dt>
<dd>Move to the start of the line. This is the same as the <code>Home</code> key if you have one.
</dd>
<dt><code>C-e</code></dt>
<dd>Move to the end of the line. This is the same as the <code>End</code> key if you have one.
</dd>
<dt><code>M-f</code></dt>
<dd>Move forward a word. A word is what you would expect, a sequence of letters and numbers.
</dd>
<dt><code>M-b</code></dt>
<dd>Move backward a word.
</dd>
<dt><code>C-l</code></dt>
<dd>Clear the screen, reprinting the current line at the top.
</dd>
</dl>
<h2 id="example">Example</h2>
<p>This is a little difficult to demonstrate on an audio podcast, but hopefully the description will be understandable.</p>
<ul>
<li>In a terminal type: <code>The quick brown fox</code>
<ul>
<li>After the 'x' of 'fox' press <code>M-b</code>. The cursor moves to the 'f' of 'fox'.</li>
<li>Press <code>M-b</code> again. The cursor moves to the 'b' of 'brown'.</li>
<li>Press <code>C-d</code>. The 'b' is deleted and the cursor is on the 'r' of 'brown'.</li>
<li>Press <code>C-_</code>. The 'b' is restored, but the cursor is on the 'r' still.</li>
<li>Press <code>C-_</code> again. The whole line disappears.</li>
</ul></li>
</ul>
<h2 id="links">Links</h2>
<ul>
<li>Wikipedia article on <em>GNU Readline</em>: <a href="https://en.wikipedia.org/wiki/GNU_Readline" class="uri">https://en.wikipedia.org/wiki/GNU_Readline</a></li>
<li><em>GNU Readline</em> manual: <a href="http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html" class="uri">http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html</a></li>
</ul>
<!--
vim: syntax=markdown:ts=4:sw=4:ai:et:tw=78:fo=tcqn:fdm=marker
-->
</article>
</main>
</div>
</body>
</html>