Skip to content

Commit a5db45f

Browse files
added mini post on bindings keys via inputrc
1 parent d7fe14b commit a5db45f

File tree

10 files changed

+46
-6
lines changed

10 files changed

+46
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
6464

6565
## Mini blog posts
6666

67+
* [Better bindings for command line history search](https://learnbyexample.github.io/mini/better-bindings-cli-history-search/)
6768
* [OS installation woes](https://learnbyexample.github.io/mini/os-installation-woes/)
6869
* [Basic examples for the Linux date command](https://learnbyexample.github.io/mini/linux-date-command-examples/)
6970
* [CLI text editing with ed](https://learnbyexample.github.io/mini/cli-text-editing-with-ed/)

atom.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,32 @@
55
<link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
66
<link href="https://learnbyexample.github.io"/>
77
<generator uri="https://www.getzola.org/">Zola</generator>
8-
<updated>2025-05-19T00:00:00+00:00</updated>
8+
<updated>2025-05-21T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>Better bindings for command line history search</title>
12+
<published>2025-05-21T00:00:00+00:00</published>
13+
<updated>2025-05-21T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/mini/better-bindings-cli-history-search/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/mini/better-bindings-cli-history-search/</id>
16+
<content type="html">&lt;p&gt;Do you find it confusing to use &lt;code&gt;Ctrl+r&lt;&#x2F;code&gt; for searching a command from shell history? I have the following mappings in the &lt;code&gt;~&#x2F;.inputrc&lt;&#x2F;code&gt; file, so that I can use the &lt;code&gt;↑&lt;&#x2F;code&gt; and &lt;code&gt;↓&lt;&#x2F;code&gt; arrow keys instead.&lt;&#x2F;p&gt;
17+
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;quot;\e[A&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; history-search-backward
18+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;quot;\e[B&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; history-search-forward
19+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
20+
&lt;p&gt;Normally, when you use the &lt;code&gt;↑&lt;&#x2F;code&gt; arrow key, you&#x27;ll get the previous command from the history. You can repeatedly press the key to get more entries. With the above settings active, this behavior will change if you have some characters already typed before pressing the arrow key — you&#x27;ll only get entries from the history that match these characters from the start of the command. If there are multiple matches, you can use the &lt;code&gt;↑&lt;&#x2F;code&gt; and &lt;code&gt;↓&lt;&#x2F;code&gt; keys repeatedly to move backwards and forwards through the list.&lt;&#x2F;p&gt;
21+
&lt;p&gt;If you want the matching to happen anywhere in command (same behavior as &lt;code&gt;Ctrl+r&lt;&#x2F;code&gt; and &lt;code&gt;Ctrl+s&lt;&#x2F;code&gt;), use the following lines instead:&lt;&#x2F;p&gt;
22+
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;quot;\e[A&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; history-substring-search-backward
23+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;quot;\e[B&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; history-substring-search-forward
24+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
25+
&lt;p&gt;The &lt;code&gt;~&#x2F;.inputrc&lt;&#x2F;code&gt; file affects any shell using the &lt;code&gt;readline&lt;&#x2F;code&gt; library (for example, programming language REPLs). You can use the &lt;code&gt;bind&lt;&#x2F;code&gt; command and put them in, &lt;code&gt;~&#x2F;.bashrc&lt;&#x2F;code&gt; for example, to affect only that particular shell.&lt;&#x2F;p&gt;
26+
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;bind &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;&amp;quot;\e[A&amp;quot;: history-search-backward&amp;#39;
27+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;bind &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;&amp;quot;\e[B&amp;quot;: history-search-forward&amp;#39;
28+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
29+
&lt;blockquote&gt;
30+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; See &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;title&#x2F;Readline&quot;&gt;wiki.archlinux: readline&lt;&#x2F;a&gt; for more details and examples.&lt;&#x2F;p&gt;
31+
&lt;&#x2F;blockquote&gt;
32+
</content>
33+
</entry>
1034
<entry xml:lang="en">
1135
<title>Customizing pandoc to generate beautiful pdf and epub from markdown</title>
1236
<published>2025-05-19T00:00:00+00:00</published>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>Better bindings for command line history search</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="Better bindings for command line history search" property=og:title><meta content=website property=og:type><meta content="Using .inputrc to remap key bindings for cli history search." property=og:description><meta content=https://learnbyexample.github.io/mini/better-bindings-cli-history-search/ property=og:url><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/mini/better-bindings-cli-history-search/>Better bindings for command line history search</a></h1><div class=post__meta><span class=post__time>2025-05-21</span></div></header><div class=post-content><p>Do you find it confusing to use <code>Ctrl+r</code> for searching a command from shell history? I have the following mappings in the <code>~/.inputrc</code> file, so that I can use the <code></code> and <code></code> arrow keys instead.<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#d07711;>"\e[A"</span><span style=color:#5597d6;>:</span><span> history-search-backward
2+
</span><span style=color:#d07711;>"\e[B"</span><span style=color:#5597d6;>:</span><span> history-search-forward
3+
</span></code></pre><p>Normally, when you use the <code></code> arrow key, you'll get the previous command from the history. You can repeatedly press the key to get more entries. With the above settings active, this behavior will change if you have some characters already typed before pressing the arrow key — you'll only get entries from the history that match these characters from the start of the command. If there are multiple matches, you can use the <code></code> and <code></code> keys repeatedly to move backwards and forwards through the list.<p>If you want the matching to happen anywhere in command (same behavior as <code>Ctrl+r</code> and <code>Ctrl+s</code>), use the following lines instead:<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#d07711;>"\e[A"</span><span style=color:#5597d6;>:</span><span> history-substring-search-backward
4+
</span><span style=color:#d07711;>"\e[B"</span><span style=color:#5597d6;>:</span><span> history-substring-search-forward
5+
</span></code></pre><p>The <code>~/.inputrc</code> file affects any shell using the <code>readline</code> library (for example, programming language REPLs). You can use the <code>bind</code> command and put them in, <code>~/.bashrc</code> for example, to affect only that particular shell.<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#b39f04;>bind </span><span style=color:#d07711;>'"\e[A": history-search-backward'
6+
</span><span style=color:#b39f04;>bind </span><span style=color:#d07711;>'"\e[B": history-search-forward'
7+
</span></code></pre><blockquote><p><img alt=info src=/images/info.svg> See <a href=https://wiki.archlinux.org/title/Readline>wiki.archlinux: readline</a> for more details and examples.</blockquote></div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/inputrc/>#inputrc</a><a href=https://learnbyexample.github.io/tags/command-line/>#command-line</a><a href=https://learnbyexample.github.io/tags/bash/>#bash</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/mini/os-installation-woes/>OS installation woes →</a><br></div><hr color=#e6e6e6><p>📰 Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> ✅ Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> 📧 Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>

0 commit comments

Comments
 (0)