<story><title>Control-R, my favorite Unix shell command</title><url>http://blog.lerner.co.il/control-r-favorite-unix-shell-command/</url></story><parent_chain></parent_chain><comment><author>loevborg</author><text>^R is useful. But for me, there&amp;#x27;s something even more useful than searching for a string in your history using ^R: completing the line you&amp;#x27;re currently typing from your history using Alt-p. This comes in handy when you realize, after typing a few words, that you don&amp;#x27;t remember the arguments you need.&lt;p&gt;Say you start typing &amp;quot;ssh ex&amp;quot;. If you hit Alt-p, you get &amp;quot;ssh example.com&amp;quot;; hit the key another time, and you get &amp;quot;ssh example2.com&amp;quot; (or whatever you&amp;#x27;ve `ssh`ed into in the past). A matching line has to &lt;i&gt;begin with&lt;/i&gt; what you&amp;#x27;ve typed so far, so it will match &amp;quot;ssh ex.com&amp;quot; but not &amp;quot;echo ssh ex.com&amp;quot;.&lt;p&gt;To get this behavior in zsh, you can use the following:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    bindkey &amp;#x27;^[p&amp;#x27; history-beginning-search-backward
    bindkey &amp;#x27;^[n&amp;#x27; history-beginning-search-forward
&lt;/code&gt;&lt;/pre&gt;
By the way, if using the alt key is cumbersome (as it is on OSX), just press once Esc (and release) and then press p, which in the terminal is always equivalent to simultaneously pressing Alt-p. It&amp;#x27;s also easier for my fingers to reach, given the different positions of the Alt key, so I tend to use Esc instead of Alt.</text></comment>
<story><title>Control-R, my favorite Unix shell command</title><url>http://blog.lerner.co.il/control-r-favorite-unix-shell-command/</url></story><parent_chain></parent_chain><comment><author>Spittie</author><text>^R is probably my second favorite command, I prefer FiSH style (and use &lt;a href=&quot;https://github.com/zsh-users/zsh-history-substring-search&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;zsh-users&amp;#x2F;zsh-history-substring-search&lt;/a&gt; with ZSH), but since this isn&amp;#x27;t on every server I have access, it&amp;#x27;s a nice trick to remember.&lt;p&gt;My favorite one (I digress) is that you can use ^[something]^[something else] to replace [something] with [something else] in the last command. Great for typos, or for repeated commands with few different arguments.&lt;p&gt;&lt;pre&gt;&lt;code&gt;    ~ ping google.com
    ~ ^google^news.ycombinator
    ~ ping news.ycombinator.com&lt;/code&gt;&lt;/pre&gt;</text></comment>