<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Vim on David Hamann</title><link>https://davidhamann.de/tags/vim/</link><description>Recent content in Vim on David Hamann</description><generator>Hugo</generator><language>en</language><copyright>&amp;copy; David Hamann</copyright><lastBuildDate>Sun, 28 Jan 2018 00:00:00 +0000</lastBuildDate><atom:link href="https://davidhamann.de/tags/vim/feed.xml" rel="self" type="application/rss+xml"/><item><title>Using vi commands in your bash shell</title><link>https://davidhamann.de/2018/01/28/using-vi-commands-in-your-bash-shell/</link><pubDate>Sun, 28 Jan 2018 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2018/01/28/using-vi-commands-in-your-bash-shell/</guid><description>&lt;p&gt;Entering a long shell command and then moving the cursor around to correct parts of it always felt a bit clunky to me. I remembered some of the &amp;lt;ctrl&amp;gt;/&amp;lt;alt&amp;gt; key bindings but would often just end up using arrow keys or alt-click to navigate to a certain position.&lt;/p&gt;
&lt;p&gt;Today I learned that you can easily get a vi-style command line interface in bash, giving you insert and normal mode and allowing you to use a basic subset of vi commands.&lt;/p&gt;
&lt;p&gt;While an ancient feature, it was new to me. Here&amp;rsquo;s how to do it.&lt;/p&gt;
&lt;h2 id="set-shell-option-for-vi-style-editing"&gt;Set shell option for vi-style editing&lt;/h2&gt;
&lt;p&gt;To enable vi-style editing, you set the vi option:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;set -o vi
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you want to keep using the option, make sure to add it to your &lt;code&gt;.bash_profile&lt;/code&gt; or &lt;code&gt;.bashrc&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="start-making-your-edits"&gt;Start making your edits&lt;/h2&gt;
&lt;p&gt;Once you have the above command executed, you can start using the cli just like vi.&lt;/p&gt;
&lt;p&gt;A couple of things to be aware about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You are directly placed in insert mode, not in normal mode.&lt;/li&gt;
&lt;li&gt;This is not a full vi, so don&amp;rsquo;t expect every command to work.&lt;/li&gt;
&lt;li&gt;You &lt;em&gt;can&lt;/em&gt; get a full vi/vim, if you really want to 🤓 (see next section).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="more-complex-edits"&gt;More complex edits&lt;/h2&gt;
&lt;p&gt;If the implemented commands are not enough to edit your one-liner, you can always request a fully-fledged vim and open the command in a temp file.&lt;/p&gt;
&lt;p&gt;To do that, press &lt;code&gt;v&lt;/code&gt; while in normal mode. This will open your default editor with a temp file. Write-quit to execute the edited command in the shell.&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 In case this doesn&amp;rsquo;t work for you, you might want to check your setting for &lt;code&gt;$VISUAL&lt;/code&gt; or add this to your &lt;code&gt;.bash_profile&lt;/code&gt;: &lt;code&gt;export VISUAL=&amp;quot;vim&amp;quot;&lt;/code&gt;
&lt;/div&gt;
</description></item></channel></rss>