<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohit Kalra</title>
    <description>The latest articles on DEV Community by Mohit Kalra (@mohitkalra).</description>
    <link>https://dev.to/mohitkalra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F65753%2Fe4392d83-c8ca-4a6e-a8fb-83a1a1cca8ec.jpeg</url>
      <title>DEV Community: Mohit Kalra</title>
      <link>https://dev.to/mohitkalra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohitkalra"/>
    <language>en</language>
    <item>
      <title>The ‘Y’ (why)  in vimrc </title>
      <dc:creator>Mohit Kalra</dc:creator>
      <pubDate>Sat, 31 Mar 2018 07:39:21 +0000</pubDate>
      <link>https://dev.to/mohitkalra/the-y-why--in-vimrc--31k4</link>
      <guid>https://dev.to/mohitkalra/the-y-why--in-vimrc--31k4</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.vim.org%2Fimages%2Fvim_editor.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.vim.org%2Fimages%2Fvim_editor.gif" alt="vim image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am an avid &lt;a href="https://www.vim.org/" rel="noopener noreferrer"&gt;vim&lt;/a&gt; user.  I have used &lt;a href="https://www.vim.org/download.php#pc" rel="noopener noreferrer"&gt;GVim&lt;/a&gt; on Windows and now I use &lt;a href="http://macvim-dev.github.io/macvim/" rel="noopener noreferrer"&gt;MacVim&lt;/a&gt; on Mac.  I also use it from the terminal when I need it.   There are many reasons why I love vim but this post is not about that or a tutorial on vim.  If vim is your editor of choice,  you will enjoy this series as I will share “why” &lt;a href="https://github.com/technochakra/config/blob/master/vimrc" rel="noopener noreferrer"&gt;my vimrc&lt;/a&gt; looks the way it does.&lt;/p&gt;

&lt;p&gt;I have read that many folks prefer a standard out of the box tool and don’t like customizing it.  I, on the contrary, like to configure vim to my exacting needs.  My vimrc is a result of my ideas and a number of copy-pastes from fellow vimmers who have shared their configurations over the internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing the vimrc file.
&lt;/h2&gt;

&lt;p&gt;In this first part, I talk about the vimrc file itself and some tips to manage it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Make vimrc always available:
&lt;/h3&gt;

&lt;p&gt;Your first goal should be that when you set up a new computer, you should be able to configure your favorite editor in the least amount of time.   Most of my settings and plug-ins are in my vimrc file.  I install all plug-ins through a plug-in manager (more on that later).&lt;/p&gt;

&lt;p&gt;To be productive in the shortest amount of time, I require my vimrc to be available to me ASAP.  I achieve this through the following ways.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I publish my vimrc to a public &lt;a href="https://github.com/technochakra/config/blob/master/vimrc" rel="noopener noreferrer"&gt;github.com repo.&lt;/a&gt;  Make sure you remove proprietary stuff that you don’t want to share  from the file before submitting it in your public repo.&lt;/li&gt;
&lt;li&gt;My vimrc is located within my data folder – a folder that contains stuff I care about. This data is regularly backed up. So, even if I don’t have access to github.com, I usually do have my vimrc available to me through the backup.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I don’t use the vimrc in the default location.  I always sync the file to a folder such as ~/config and then I modify the default vimrc file and source the file that I synced.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~
git clone https://github.com/technochakra/config.git
echo so ~/config/vimrc &amp;gt; ~/vimrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuration is code.
&lt;/h3&gt;

&lt;p&gt;As noted above, I check-in my vimrc file to github.   If you are a software developer, we have reached the age where code, infrastructure, configuration should be treated as code and regularly checked in.  vimrc falls squarely in that category as well.&lt;/p&gt;

&lt;p&gt;Reconstructing your vimrc file from scratch is painful and should not be done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Avoid the defaults:
&lt;/h3&gt;

&lt;p&gt;I realized recently that my vimrc file contained some obvious defaults.  If you look at the help of a setting and it defaults to what you need, you don’t have to have it in your vimrc file unless some plugin is overriding your defaults.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;help errorbells
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, errrorbells (a beep in case of an error) is &lt;strong&gt;off&lt;/strong&gt; by default.  So, your vimrc file does &lt;strong&gt;*not*&lt;/strong&gt; need the following line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set noerrorbells
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having a minimal vimrc file makes it more manageable and it takes you less time to figure out the setting when you revisit it after a few years.&lt;/p&gt;

&lt;h3&gt;
  
  
  Source vimrc as soon as you write it
&lt;/h3&gt;

&lt;p&gt;The following command sources my vimrc file as soon as I modify it.  This helps me try out my changes immediately, fix errors right away and gives me a vimrc file that always works.  It is also very satisfying to see your settings take effect immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;autocmd bufwritepost vimrc source ~/config/vimrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does not work when I modify the plug-ins I use but I’ll cover that later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lint free vimrc
&lt;/h3&gt;

&lt;p&gt;As noted above, I like to treat my vimrc file like code.  Well, then there is no excuse not to statically analyze it for warnings and errors.  I use &lt;a href="https://github.com/Kuniwak/vint" rel="noopener noreferrer"&gt;vint&lt;/a&gt; as my lint program.  For some reason, vint didn’t work on MacVim when called from plugins that integrate with it so I ended up using vint from the command line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vint ~/config/vimrc
Sample output: &amp;lt;some_path&amp;gt;/vimrc:1:1: Use scriptencoding when multibyte char exists (see :help :scriptencoding)_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;vint is a great tool to avoid common mistakes.  For example, I did not know about augroups until the tool flagged them for me.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;some_path&amp;gt;/vimrc:31:3: autocmd should execute in an augroup or execute with a group (see :help :autocmd) 
&amp;lt;some_path&amp;gt;/vimrc:32:3: autocmd should execute in an augroup or execute with a group (see :help :autocmd)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It turns out that by putting autocmds in an augroup, and clearing the augroup using the autocmd! command, you prevent duplication of autocmds in your augroup when your source the file again.   This keeps things clean and optimal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;augroup NERDTREE 
autocmd! 
autocmd vimenter * NERDTree
augroup END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Managing your vimrc file is fairly simple.  It helps to constantly clean it up and keep it minimal.  Now that we have the structure for maintaining our vimrc file, I will discuss the settings I use in subsequent posts.&lt;/p&gt;

</description>
      <category>vim</category>
    </item>
  </channel>
</rss>
