<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Vim | Alex Ho</title>
    <link>/tags/vim/</link>
      <atom:link href="/tags/vim/index.xml" rel="self" type="application/rss+xml" />
    <description>Vim</description>
    <generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-gb</language><lastBuildDate>Mon, 31 Jan 2022 16:00:00 +0000</lastBuildDate>
    <image>
      <url>/media/icon_hu_13d0a7a216a183f.png</url>
      <title>Vim</title>
      <link>/tags/vim/</link>
    </image>
    
    <item>
      <title>vim</title>
      <link>/post/vim/</link>
      <pubDate>Mon, 31 Jan 2022 16:00:00 +0000</pubDate>
      <guid>/post/vim/</guid>
      <description>&lt;p&gt;I have been actively using &lt;code&gt;vim&lt;/code&gt; (technically 
) for
development at work and at home for almost 4 years (and was switching between
between &lt;code&gt;vim&lt;/code&gt; and &lt;code&gt;atom&lt;/code&gt; the year before). I like it mainly because it allows me
to use modal editing which is faster for me compared to 
 or 
.  Another
reason is that almost all servers has either &lt;code&gt;vi&lt;/code&gt; or &lt;code&gt;vim&lt;/code&gt; available. One more
reason is that I am pretty bad at using point-and-click interfaces and I would
like to stick to command line tools as much as possible. Perhaps the most
important reason, it looks cool to code in a terminal, isn&amp;rsquo;t it?&lt;/p&gt;
&lt;p&gt;The learning curve of &lt;code&gt;vim&lt;/code&gt; is pretty steep at the beginning. Luckily, I got
myself a little head start by using 
. I then forked it and made 
. The way that I start learning
&lt;code&gt;vim&lt;/code&gt; is by going through

 and try to
understand the mappings involved and try it out in &lt;code&gt;vim&lt;/code&gt;. In retrospect, this is
probably not the best way to start and I should have start with &lt;code&gt;vimtutor&lt;/code&gt; and
go through the basics instead. As many people have already suggested, I did not
try to use it at work at the beginning as this would affect my productivity too
much. After trying it out for 8-10 weekends with my hobby projects, I felt more
confident with &lt;code&gt;vim&lt;/code&gt; and tried to use &lt;code&gt;vim&lt;/code&gt; and Visual Studio Code at work.
After 3 or 4 months, I was getting more used to &lt;code&gt;vim&lt;/code&gt; and use it solely at work.
During this process, one of the things I have done to help myself learning more
about &lt;code&gt;vim&lt;/code&gt; is to consume a large amount of YouTube videos where people
demonstrate their skills with &lt;code&gt;vim&lt;/code&gt;. Here is a list of my favourite channels.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Besides YouTube videos, I learned quite a lot by reading through sub-reddits of

 and

.&lt;/p&gt;
&lt;p&gt;It is amazing that I can still learn something new about &lt;code&gt;vim&lt;/code&gt; everyday now
although I have been using it for more than 4 years full-time. The rest of this
post is not meant to be a tutorial but rather showing what &lt;code&gt;vim&lt;/code&gt; can do with
some of my configuration and I hope this can inspire someone to use &lt;code&gt;vim&lt;/code&gt; as
their editor.&lt;/p&gt;
&lt;p&gt;Apart from 

configuration, there are plug-ins to make life easier to use &lt;code&gt;vim&lt;/code&gt;. There are
many plug-in managers available. I inherited Jess Frazelle&amp;rsquo;s way of doing it by
using 
 from Tim Pope. I like
this way of managing it as it is purely &lt;code&gt;git&lt;/code&gt; operations (although everyone else
is using 
 which is good as
well). The rest of this post is based on 
 and many of the key bindings
(or mappings) are not the same as the built-in ones.&lt;/p&gt;
&lt;p&gt;If the following is too long a read for you, feel free to jump to 
.&lt;/p&gt;
&lt;h3 id=&#34;essentials&#34;&gt;Essentials&lt;/h3&gt;
&lt;p&gt;To be able to know what mappings are available is important for learning so that
we would know what we can try. &lt;code&gt;:Maps&lt;/code&gt; (with help of plug-in

) does exactly this.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/find-mapping.gif&#34; alt=&#34;find-mapping&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;File searching is also available using &lt;code&gt;ctrl+p&lt;/code&gt;. It is like file search in any
other editors or IDEs. Behind the scene, it is using &lt;code&gt;fzf&lt;/code&gt; and

.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/file-search.gif&#34; alt=&#34;file-search&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;h3 id=&#34;navigation&#34;&gt;Navigation&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;^&lt;/code&gt; can be used to jump to the first character of the current line.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/first-character.gif&#34; alt=&#34;first-character&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;$&lt;/code&gt; can be used to jump to the end of the current line.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/last-character.gif&#34; alt=&#34;last-character&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;V&lt;/code&gt; can be used to visually select a line. Sometimes, one may want to select the
previous visual select by &lt;code&gt;gv&lt;/code&gt;. The following example visually select a bullet
point, copy it, move the cursor somewhere else and select the paragraph again.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/re-select-visual.gif&#34; alt=&#34;re-select-visual&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[s&lt;/code&gt; and &lt;code&gt;]s&lt;/code&gt; can be used to jump to the previous and the next spelling mistake
respectively. When the cursor is on the spelling mistake, &lt;code&gt;z=&lt;/code&gt; can be used show
a list of suggested correct spellings. The following example jumps to the
previous spelling mistake and take the first suggestion to fix it by &lt;code&gt;[s1z=&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/fix-spelling.gif&#34; alt=&#34;fix-spelling&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;%&lt;/code&gt; can be used to jump between square bracket or parentheses surrounding the
current cursor.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/jump-between-brackets.gif&#34; alt=&#34;jump-between-brackets&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[{&lt;/code&gt; and &lt;code&gt;]}&lt;/code&gt; can be used to jump to the previous and the next curly brackets
respectively.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/jump-between-curly-brackets.gif&#34; alt=&#34;jump-between-curly-brackets&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;:jumps&lt;/code&gt; shows the list of locations of previous jumps made. &lt;code&gt;ctrl+o&lt;/code&gt; and
&lt;code&gt;ctrl+i&lt;/code&gt; jumps to the previous and the next position respectively.&lt;/p&gt;
&lt;h3 id=&#34;editing&#34;&gt;Editing&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;S&lt;/code&gt; starts cursor in the current line with correct indentation. It also wipes
out the current line as well.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/start-with-indent.gif&#34; alt=&#34;start-with-indent&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;

















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/wipe-and-start-with-indent.gif&#34; alt=&#34;wipe-and-start-with-indent&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[+space&lt;/code&gt; and &lt;code&gt;]+space&lt;/code&gt; can be used to add empty line above and below the
current line respectively. The following example uses &lt;code&gt;2[space&lt;/code&gt; to add to empty
lines above the cursor.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/add-empty-lines.gif&#34; alt=&#34;add-empty-lines&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[e&lt;/code&gt; and &lt;code&gt;]e&lt;/code&gt; swap the current line with the line above and below respectively.
The following example demonstrates &lt;code&gt;[e&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/swap-lines.gif&#34; alt=&#34;swap-lines&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;With cursor in parentheses of a method/function parameters, &lt;code&gt;gs&lt;/code&gt; can be used to
visually select a parameter and swap it. The following example selects the
parameter to be swapped by using &lt;code&gt;j&lt;/code&gt; and &lt;code&gt;k&lt;/code&gt;, and the parameter is moved around
by using &lt;code&gt;h&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/swap-parameters.gif&#34; alt=&#34;swap-parameters&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;The same command can be used to swap a visually selected list as well.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/swap-list.gif&#34; alt=&#34;swap-list&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;Change operation can be pretty powerful. For example, &lt;code&gt;2ci(&lt;/code&gt; can be used to
change all the text within two parentheses.&lt;/p&gt;
&lt;p&gt;















&lt;figure  &gt;
  &lt;div class=&#34;flex justify-center	&#34;&gt;
    &lt;div class=&#34;w-full&#34; &gt;&lt;img src=&#34;./images/change-in-two-parentheses.gif&#34; alt=&#34;change-in-two-parentheses&#34; loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;The above are some of the very basic stuff. I will cover more in the future blog
posts.&lt;/p&gt;
&lt;p&gt;Enjoy coding.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
