Skip to content

Commit dbf8f9c

Browse files
updated cli history search post
1 parent a5db45f commit dbf8f9c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

atom.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
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-21T00:00:00+00:00</updated>
8+
<updated>2025-05-27T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
1010
<entry xml:lang="en">
1111
<title>Better bindings for command line history search</title>
1212
<published>2025-05-21T00:00:00+00:00</published>
13-
<updated>2025-05-21T00:00:00+00:00</updated>
13+
<updated>2025-05-27T00:00:00+00:00</updated>
1414
<link rel="alternate" href="https://learnbyexample.github.io/mini/better-bindings-cli-history-search/" type="text/html"/>
1515
<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;
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. Note that this assumes you are using Emacs-style key bindings instead of Vi mode.&lt;&#x2F;p&gt;
1717
&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
1818
&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
1919
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
@@ -26,9 +26,13 @@
2626
&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;
2727
&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;
2828
&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;
29+
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
30+
&lt;ul&gt;
31+
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;title&#x2F;Readline&quot;&gt;Introduction to readline&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
32+
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;cupfullofcode.com&#x2F;blog&#x2F;2013&#x2F;07&#x2F;03&#x2F;efficient-command-line-navigation&#x2F;index.html&quot;&gt;Efficient command line navigation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
33+
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;junegunn&#x2F;fzf&quot;&gt;fzf: general purpose command line fuzzy finder&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
34+
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;mikebian.co&#x2F;supercharged-zsh-command-history&#x2F;&quot;&gt;Supercharged zsh command history&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
35+
&lt;&#x2F;ul&gt;
3236
</content>
3337
</entry>
3438
<entry xml:lang="en">
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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
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><div class=post-toc id=post-toc><h2 class=post-toc-title>Contents</h2><div class="post-toc-content always-active"><nav id=TableOfContents><ul><li><a class=toc-link href=https://learnbyexample.github.io/mini/better-bindings-cli-history-search/#further-reading>Further Reading</a></ul></nav></div></div><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. Note that this assumes you are using Emacs-style key bindings instead of Vi mode.<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
22
</span><span style=color:#d07711;>"\e[B"</span><span style=color:#5597d6;>:</span><span> history-search-forward
33
</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
44
</span><span style=color:#d07711;>"\e[B"</span><span style=color:#5597d6;>:</span><span> history-substring-search-forward
55
</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'
66
</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>
7+
</span></code></pre><h2 id=further-reading>Further Reading</h2><ul><li><a href=https://wiki.archlinux.org/title/Readline>Introduction to readline</a><li><a href=https://cupfullofcode.com/blog/2013/07/03/efficient-command-line-navigation/index.html>Efficient command line navigation</a><li><a href=https://github.com/junegunn/fzf>fzf: general purpose command line fuzzy finder</a><li><a href=https://mikebian.co/supercharged-zsh-command-history/>Supercharged zsh command history</a></ul></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>

sitemap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</url>
129129
<url>
130130
<loc>https://learnbyexample.github.io/mini/better-bindings-cli-history-search/</loc>
131-
<lastmod>2025-05-21</lastmod>
131+
<lastmod>2025-05-27</lastmod>
132132
</url>
133133
<url>
134134
<loc>https://learnbyexample.github.io/mini/cli-computing-sales/</loc>

0 commit comments

Comments
 (0)