{"componentChunkName":"component---src-pages-author-author-yaml-id-js","path":"/author/shubhankar-khare/","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"id":"cb7b9df3-1aca-5e57-8d28-8bd2cafd9bcc","html":"<h2 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prerequisites</h2>\n<p>You should know the basics of Vim beforehand. You may refer to a previous blog <a href=\"https://www.loginradius.com/blog/engineering/vim-getting-started/\">Vim: Getting started</a>.</p>\n<p>This tutorial explores the following concepts:</p>\n<ul>\n<li>Macros</li>\n<li>Buffers and splitting</li>\n<li>Global  command</li>\n</ul>\n<p>In addition, this tutorial explores a few other tips and tricks. It is not uncommon for folks who have been using Vim for a long time and not being familiar with these handy, useful features.</p>\n<h2 id=\"macros\" style=\"position:relative;\"><a href=\"#macros\" aria-label=\"macros permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Macros</h2>\n<p>You don't want to miss out on macros if you want to level up your Vim game. Vim macro is a powerful feature that allows you to record a sequence of keys on the fly. It helps you to automate a lot of stuff. </p>\n<p>Macros are based on the concept of registers. If you don't know what registers are, you can think of them as a bunch of spaces in memory that Vim uses to store some text.</p>\n<p>Macros are editable registers, which you can record, store, and edit whenever you want.</p>\n<p>Here's the basic syntax of  macros:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">q&lt;key you want to record your macro into&gt;&lt;series of commands&gt;q</span></code></pre>\n<p>Example:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">q1f;xq</span></code></pre>\n<p>Let's break it down for you:</p>\n<p>q : Starts recording a macro<br>\n1 : The recorded macro will be stored on key 1<br>\nf;x : Find the first occurrence of <code>;</code>in that line and delete <code>;</code><br>\nq : stop recording the macro  </p>\n<p>That's it. Now, you can use this macro by <code>@&#x3C;your key></code> i.e <code>@1</code></p>\n<p>If you want to repeat a macro <em>n</em> number of times, then <code>n@1</code>is the syntax.</p>\n<h3 id=\"use-case\" style=\"position:relative;\"><a href=\"#use-case\" aria-label=\"use case permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Use Case</h3>\n<p>Not impressed yet? Huhh! Let's show you a practical use case to demonstrate the power of a macro. I work in ReactJs a lot and like to export all my components in one file. Let's try exporting 99 HeroBlocks in one go.</p>\n<p>The desired result is:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">export {default as HeroBlock1 } from &#39;./HeroBlock1/HeroBlock1.js&#39;</span>\n<span class=\"grvsc-line\">export {default as HeroBlock2 } from &#39;./HeroBlock1/HeroBlock2.js&#39;</span>\n<span class=\"grvsc-line\">export {default as HeroBlock3 } from &#39;./HeroBlock1/HeroBlock3.js&#39;</span>\n<span class=\"grvsc-line\">...</span>\n<span class=\"grvsc-line\">..</span>\n<span class=\"grvsc-line\">so on</span></code></pre>\n<p>Perform <code>vim index.js</code></p>\n<p>And, write this line:</p>\n<p><code>export {default as HeroBlock1 } from './HeroBlock1/HeroBlock1.js'</code></p>\n<p>Now, follow along:</p>\n<p><code>q1yyp4E ^A6e ^Aq</code></p>\n<p>Breaking it down:</p>\n<p>q1 : Start recording a macro in key 1.<br>\nyy : yank the current line.<br>\np : paste the yanked line.<br>\n4E : Get the cursor to 1 of Heroblock1. (<em><code>f1</code> might be tempting but it will give you wrong results as not all lines will have 1, they can have any number. Try making the macro very generalized.</em>)<br>\n^A : this is <code>ctrl + a</code>. It increments the current version by one.<br>\n6e : Get the cursor to the second number.<br>\n^A : increment the number by one.<br>\nq : stop recording.  </p>\n<p>Now, to repeat your macro 99 times:</p>\n<p><code>99@1</code></p>\n<p>And that's all.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 53.38461538461539%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABvUlEQVQoz22Qa5OaMBSGIzDtOnWXWkAIIhCEXJA1ARFUZMHVma792P//Yxppa68zz5w5+fDM++aAyj52+NKmXw70WrhNy9vz9rWKdrFeoseNNxaLyQa+y2wFmxKV+JMcm3tsNf60BgW8HOLPDbm27Fp7Tceb1+KlDCo05ssxR++fw4e1p6X2iBgD7sM6fCqRvnU/FCC1zzm6bMLTIT6XsD6uqi6rC5gjhcYai7U00dJQpXOFWINsjoilUHMAEP3AF73w+zzoM2N7TKs+q7dQJIo02VJlREvl4isUjshskI2fAPxYc6/jfr9e9Ktp2bLqdJNzKUszVKicd9n5W57UwutksvTTT2UzyBso0OhWO1FZorFIZQuFOkOy9bucDMnC72R5Nt3sWPWS1cIRIaBYY3joHCjU/TPzP8lsWkr5mO3WDncBlndCKpWF5yNi/2P++LPw+lvyIO/Tqs3qzOYzgB1A7swAMb4jK9yvHY0LPu/EoufeiX4s96xqWF2yEvvPyCUhJAjSX7jEHmMdRDpATyACYn5dWjkyODJEoK9ie5U4WQyzcLYKZ2lgstBKgwH5jN11aOYMvuXzr1Xw9g0ZnFaA2Q5PqwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"macro demo\"\n        title=\"macro demo\"\n        src=\"/static/3fc1ce475f85e20f3e8953cea9830341/e5715/vim-macro-demo.png\"\n        srcset=\"/static/3fc1ce475f85e20f3e8953cea9830341/a6d36/vim-macro-demo.png 650w,\n/static/3fc1ce475f85e20f3e8953cea9830341/e5715/vim-macro-demo.png 768w,\n/static/3fc1ce475f85e20f3e8953cea9830341/26c3a/vim-macro-demo.png 1907w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"buffers--splitting\" style=\"position:relative;\"><a href=\"#buffers--splitting\" aria-label=\"buffers  splitting permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Buffers &#x26; Splitting</h2>\n<p>In simple terms, a <em>buffer</em> is a file that has been loaded into memory. Everything you do in Vim is in a buffer. You can list all the buffers by <code>:buffers</code>. And then, if you want to check out a particular buffer, use <code>:b n</code> -- where n is the buffer number. </p>\n<p>If you want to delete a buffer, use <code>:bd n</code> is the command.</p>\n<p>To create a new buffer in the same view -- creating a split in the current window -- use <code>:sp filename</code>. </p>\n<p>For a vertical split, use <code>:vsp filename</code>.</p>\n<blockquote>\n<p>To be honest, using buffer numbers to switch buffers is not what I prefer to do. I prefer to switch based on what I see, like <code>ctrl-w</code> then <code>j</code>to focus on a buffer below if I'm splitting the window. <code>:tabprevious</code> to move a tab on the left if I'm using tabs.</p>\n</blockquote>\n<p>Here are some key bindings you might want to use for a smooth workflow.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">nnoremap &lt;C-t&gt; :tabnew&lt;CR&gt;</span>\n<span class=\"grvsc-line\">nnoremap &lt;C-Left&gt; :tabprevious&lt;CR&gt;</span>\n<span class=\"grvsc-line\">nnoremap &lt;C-Right&gt; :tabnext&lt;CR&gt;</span>\n<span class=\"grvsc-line\">nnoremap &lt;C-J&gt;  &lt;C-W&gt;&lt;C-J&gt;</span>\n<span class=\"grvsc-line\">nnoremap &lt;C-K&gt;  &lt;C-W&gt;&lt;C-K&gt;</span>\n<span class=\"grvsc-line\">nnoremap &lt;C-L&gt;  &lt;C-W&gt;&lt;C-L&gt;</span>\n<span class=\"grvsc-line\">nnoremap &lt;C-H&gt;  &lt;C-W&gt;&lt;C-H&gt;</span></code></pre>\n<h2 id=\"global-command\" style=\"position:relative;\"><a href=\"#global-command\" aria-label=\"global command permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Global Command</h2>\n<p>The global command in Vim is very powerful and will solve a lot of your problems quickly.</p>\n<p>The basic syntax goes something as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:[range]global/{pattern}/{command}</span></code></pre>\n<p>Let's go through some use cases to learn more about it.</p>\n<p>The following will delete any line containing the word console in the entire file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:g/console/d</span></code></pre>\n<p>The following will delete any line between line 10-20 containing the word console in it:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:10,20g/console/d</span></code></pre>\n<p>You can even do the inverse of it by using <code>:g!</code></p>\n<p>The following will delete any line <strong>not</strong> containing the word console in it in the entire file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:g!/console/d</span></code></pre>\n<p>You can even combine the two.</p>\n<p>The following will delete any line containing <em>console</em> and not containing <em>hello</em> in it in the entire file.</p>\n<p>The global command can work on any regular expression, which makes it even more powerful, provided you're creative enough...</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:g/console/g!/Hello/d</span></code></pre>\n<p>The following will delete any line starting with <code>#</code> i.e., comments in python will be deleted in one go:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:g/^#/d</span></code></pre>\n<p>So far, we've been using d as the command, but it can be anything else like <code>m</code> for move <code>t</code> for copy etc.</p>\n<p>One of the very powerful commands is <code>norm</code>. This command allows you to do anything that would have worked in normal mode.</p>\n<p>The following will comment out all the print statements in a python code in one go.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:g/print/norm I#</span></code></pre>\n<p>The global command can be coupled with macros using <em>norm</em>, which means you can apply a macro to certain lines matching the regex given. This was enough to blow my mind, and it made the time I spent reading about Vim worthy.</p>\n<p>Here's the syntax for using macros with global commands:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">:g/const/normal @q</span></code></pre>\n<h2 id=\"you-made-it\" style=\"position:relative;\"><a href=\"#you-made-it\" aria-label=\"you made it permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>You Made It</h2>\n<p>Congratulations! You made it this far. You now have leveled up your Vim game. All these tips and tricks will eventually be useful to you. Here's a little something for reading this far: <a href=\"https://pintovim.dev/\">Pintovim</a> You can use this tool to make your own customized Vim color scheme.</p>\n<p>Thanks for reading!</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"title":"How to Upgrade Your Vim Skills","author":{"id":"Shubhankar Khare","github":"iamshubhankarkhare","avatar":null},"date":"September 23, 2021","updated_date":null,"tags":["Vim","Text Editor","UNIX"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/0e8a15779baa24ee0c8d1487ce2f4794/ee604/Vim.png","srcSet":"/static/0e8a15779baa24ee0c8d1487ce2f4794/69585/Vim.png 200w,\n/static/0e8a15779baa24ee0c8d1487ce2f4794/497c6/Vim.png 400w,\n/static/0e8a15779baa24ee0c8d1487ce2f4794/ee604/Vim.png 800w,\n/static/0e8a15779baa24ee0c8d1487ce2f4794/f3583/Vim.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"fields":{"authorId":"Shubhankar Khare","slug":"/engineering/guest-post/vim-level-up/"}}},{"node":{"id":"2651ac20-8db3-54c4-85aa-459ab1043fdf","html":"<p>The acronym for Vim is Vi IMproved. Written by <a href=\"https://en.wikipedia.org/wiki/Bram_Moolenaar\">Bram Moolenaar</a>, it is a free and open-source text editor. It was first released for UNIX variants in 1991, and its primary purpose was to develop the Vi editor, which was released back in 1976.</p>\n<p>Vim is Vi's newest and most popular reincarnation that supports both text and graphical interfaces and is supported on any known platform.</p>\n<p>The issue with learning Vim is not that it's challenging to do. It's that you have to continue to do it. This guide aims to break the loop so that for the last time, you can learn it.</p>\n<p>The purpose of this tutorial is to take you through every step of progress from understanding the philosophy of Vim. In short, in a way that sticks with you for a lifetime, we're going to master Vim.</p>\n<p>Let's start off!</p>\n<h2 id=\"what-is-vim\" style=\"position:relative;\"><a href=\"#what-is-vim\" aria-label=\"what is vim permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Vim?</h2>\n<p>Vim is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface). It is mainly because it can be managed entirely without menus or a mouse with a keyboard.</p>\n<p>For the following five reasons, I feel people should use Vim:</p>\n<ol>\n<li>It's omnipresent. You don't have to think about learning about several boxes with a new editor.</li>\n<li>It is highly scalable. You can use it only to edit configuration files or become your entire forum for writing.</li>\n<li>It has a shallow memory footprint.</li>\n<li>It's command-centered. With a few commands, you can perform complex text-related tasks.</li>\n<li>It is highly configurable and uses simple text files to store its settings.</li>\n</ol>\n<h2 id=\"why-use-vim\" style=\"position:relative;\"><a href=\"#why-use-vim\" aria-label=\"why use vim permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why Use Vim?</h2>\n<p>In all POSIX systems, Vim is the default fallback editor. Vim is sure to be open, whether you have just installed the operating system, or you have booted into a minimal system repair environment, or you are unable to access any other editor. While you can switch out other tiny editors on your systems, such as GNU Nano or Jove, it's Vim that's all but guaranteed to be on every other system in the world.</p>\n<p>In short, I think competence with Vim should be considered the way you view competence with your native language, or simple maths, etc. In technology, so much begins with understanding your editor.</p>\n<p>Also, It is <strong>extremely customizable</strong> and you can adapt it to your way of coding and your way of doing things.\nTo give you a taste of vim , below are a few commands frequently used to code at lightning speed:</p>\n<ul>\n<li>hjkl : move the cursor around to left, down, up, and right respectively.</li>\n<li>7j : move 7 lines down.</li>\n<li>w : move a word forward</li>\n<li>ctrl + f : move down a page</li>\n<li>ctrl + b : move up a page</li>\n<li>gg : move to the top of the document</li>\n<li>G : move to the bottomost of the document</li>\n<li>dw : delete a word</li>\n<li>d6w : delete 6 words</li>\n<li>dt> : delete till  <code>></code></li>\n<li>di] : delete everything inside <code>[ ]</code></li>\n<li>dd : delete whole line</li>\n<li>4dd : delete 4 lines</li>\n<li>yy : yank a line ( yank is copy )</li>\n<li>cc : change a line ( change is delete and go in insert mode )</li>\n<li>cap : change a paragraph</li>\n<li><code>.</code> : repeat last command</li>\n<li>f' : find first occurance of <code>'</code></li>\n<li>f'ci'hello : _find the next  <code>'</code> then change everything inside <code>'</code> for <code>hello</code></li>\n</ul>\n<p>The list goes on and on... </p>\n<p>Basically we have standard keybindings like d for delete, c for change, f for find etc. and we can pair them with numbers to repeat that action n number of times. Moreover doubling a command like so <code>yy</code> makes the command operate on the entire line.</p>\n<p>So to sum up,</p>\n<blockquote>\n<p>Vim is for <strong>programmers who want to raise their game</strong>. In the hands of an expert, It shreds text at the speed of thought.</p>\n</blockquote>\n<h4 id=\"how-to-use-vim\" style=\"position:relative;\"><a href=\"#how-to-use-vim\" aria-label=\"how to use vim permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to use Vim</h4>\n<p> Well, there is a learning curve, but it's worth it. Although this steep curve is exaggerated in the online world and the <strong>quitting vim joke</strong> is getting very old (It's:q btw).</p>\n<p> Install Vim <code>sudo apt-get vim or pacman -S vim</code> for Linux user and type <code>vim &#x3C;filename></code> in your terminal. Press <code>i</code> to go to insert mode. Type some gibberish. Press <code>:wq</code> to save and quit . <code>:q!</code> to quit without saving.</p>\n<p> First of all, don't get disheartened when you see VIM for the first time, it's known to make a <strong>horrible first impression.</strong> We'll learn to customize it later in the blog.</p>\n<p> <span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 585px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 49.05982905982906%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAIAAAA7N+mxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABYElEQVQoz1VRXW+CQBAEBEStoig1TeOzVflGvDvuABGEWJu+2P//W7qAgiaTzWSZnZ09uLFHuW3A7Q4vgE7T3AQdf4CvIQAXdui520xKNpHtUDCx4jIA8BdBC9HAd2/AZl/XQLTwW5AMvGgcJCpOwetF0AbpGYg30NCPhn4MFfbMSLag51X2s8quq9N1GRVTfBrt44HHmio7tGfibrjvUpichznolnE5p7lOc42cllGpswK8APAVjCBLN9zGhp2CiUZgQVItzGbprxp9Dz3Wd6hWZ5kcEsUDDa5e8X5z47ENdHaG5SotteI2Yhdpf5TcSLCZaIcqSmcEksNpkWzTpwd7DH8eL5MgeWfFR3nTiz+VZGp8HWc32U8WIVwByfM5ySBF92CiSTgDAXiLcGBk4uofmkiwCO8wvtqDqqaJqw4ANLW+gvLlyjWktSu1tSFrByA/OJCpgwdbH7iy9SYW+gfI+Fjjv9gzagAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"BadVim\"\n        title=\"BadVim\"\n        src=\"/static/c404bd0ddd9d5a787c6e368baf271819/78a22/BadVim.png\"\n        srcset=\"/static/c404bd0ddd9d5a787c6e368baf271819/78a22/BadVim.png 585w\"\n        sizes=\"(max-width: 585px) 100vw, 585px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p> To get started, get your hands dirty on <strong>vimtutor</strong> . It's a 20-30 minute vim tutorial which teaches you all the basics. Just type <code>vimtutor</code> in your terminal (in a machine where you have vim installed) to open it.</p>\n<p><strong>Try  <a href=\"https://vim-adventures.com/\">Vim Adventures</a></strong>. An interactive game that teaches you vim skills in a step by step manner and lets you unlock new abilities after you've proved your worth with the previous ones.</p>\n<p> Just get started with it . <strong>Learn as you go</strong> . You can always refer to the <a href=\"https://vim.rtorr.com/\">Vim CheatSheet</a> to get better. Practice makes a man perfect. Watch screencasts if that's helpful (was helpful to me).</p>\n<h2 id=\"how-do-i-configure-my-vim-\" style=\"position:relative;\"><a href=\"#how-do-i-configure-my-vim-\" aria-label=\"how do i configure my vim  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How do I configure my Vim ?</h2>\n<p>The best way to configure your Vim is through <code>.vimrc</code> file, which is hidden inside your home directory. Open a terminal and type <code>vim ~/.vimrc</code> to open your vimrc file using vim. Cool huh? Using vim to configure vim ..no? Nevermind!\nHere you can define your keybindings, set themes, install plugins etc.</p>\n<p>Here is an example of a custom keybinding\n<code>map &#x3C;C-n> :NERDTreeToggle&#x3C;CR></code>\nYou can check out this <a href=\"https://hea-www.harvard.edu/~fine/Tech/vi.html\">article</a> on keybindings and how to use them.</p>\n<p>The easiest way to download and manage plugins for vim is by using a plugin manager. There are quite a few <a href=\"https://github.com/tpope/vim-pathogen\">vim-pathogen</a> , <a href=\"https://github.com/VundleVim/Vundle.vim\">Vundle.vim</a> , <a href=\"https://github.com/junegunn/vim-plug\">Vim-plug</a> etc.\nVim-plug being my favourite. Installations and usage for each plugin manager can be found in their respective repositories.</p>\n<p>I personally like to call all my plugins in a separate file and link that file to my vimrc. Paste this line in your vimrc at the top if you want to do the same <code>source ~/.vim/plugin/plugins.vim</code>\nIn your plugins.vim file you can install different plugins like this:-</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">call plug#begin(&#39;~/.vim/plugged&#39;)</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">Plug &#39;scrooloose/nerdtree&#39;</span>\n<span class=\"grvsc-line\">Plug &#39;moll/vim-node&#39;</span>\n<span class=\"grvsc-line\">Plug &#39;yegappan/mru&#39;</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">call plug#end()</span></code></pre>\n<p>The first and last lines are for vim-plug to know what plugins are to be installed. The lines beginning with <code>Plug</code> is to install that particular plugin.</p>\n<p>Now just reload .vimrc (or quit vim and re-enter) and <code>:PlugInstall</code> to install plugins.</p>\n<h2 id=\"what-are-some-good-plugins-for-vim\" style=\"position:relative;\"><a href=\"#what-are-some-good-plugins-for-vim\" aria-label=\"what are some good plugins for vim permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What are some good plugins for Vim?</h2>\n<p>Glad you asked because Vim is no fun without plugins made by the awesome open source community.\nHere are some good plugins you should definitely install. Just search these on GitHub in case you wanna know more about them or their usage.</p>\n<ul>\n<li>scrooloose/nerdtree</li>\n<li>alvan/vim-closetag</li>\n<li>vim-scripts/vim-auto-save</li>\n<li>airblade/vim-gitgutter</li>\n<li>ervandew/supertab</li>\n<li>vim-airline/vim-airline</li>\n<li>SirVer/ultisnips</li>\n<li>honza/vim-snippets</li>\n<li>dense-analysis/ale</li>\n<li>tpope/vim-repeat</li>\n<li>ap/vim-css-color</li>\n<li>jiangmiao/auto-pairs</li>\n<li>tmhedberg/matchit</li>\n<li>kana/vim-textobj-user</li>\n<li>vim-scripts/tComment</li>\n<li>Valloric/YouCompleteMe', { 'do': './install.py --tern-completer' }</li>\n<li>prettier/vim-prettier', { 'do': 'yarn install' }</li>\n<li>jeffkreeftmeijer/vim-numbertoggle</li>\n<li>elzr/vim-json</li>\n<li>tpope/vim-markdown</li>\n<li>pangloss/vim-javascript</li>\n<li>mxw/vim-jsx</li>\n<li>jparise/vim-graphql</li>\n<li>leafgarland/typescript-vim</li>\n<li>vim-syntastic/syntastic</li>\n<li>ntpeters/vim-better-whitespace</li>\n</ul>\n<p>Pheww!!..\nSo you see there's a plugin for anything and everything. These plugins are more than enough to make vim a full-blown IDE.</p>\n<h3 id=\"summing-up\" style=\"position:relative;\"><a href=\"#summing-up\" aria-label=\"summing up permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summing up!!</h3>\n<p>VIM makes you write code at the speed of thoughts. Just get started, and the rest will follow. Steal your friend's vimrc or find one on the internet (there are tons of them) if you don't want to make one of your own.</p>\n<p>If you want to slowly blend in into the world of vim then use some vim plugin for your text editor. All popular text editors have a vim plugin ( <a href=\"https://marketplace.visualstudio.com/items?itemName=vscodevim.vim\">Here's one for VsCode </a>)\nHere you go, best of both worlds! When you're comfortable enough, go for that complete switch.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 585px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 50.94017094017094%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAIAAAA7N+mxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABv0lEQVQoz2WQu47UMBSG8xYzudnxZBInvsVOnHgS5zJCww4LSEgUjESBtA0SL4G0PRU9FdRUSDS8DT0tJXh2KBb4dOTiWP9/zn+8RutxWqZ5sXacl73gvJRt/+I1o0QpxRh1laZpAkG+iTcIIoSSJHEvAMAzxhweXl9dPdn1zuFQYvbuw6evP37xp68qTqXuuJBSKlJkCod4m2RZnm42zg5C6LmB3RnDGCeCoS16fnq5f/M22uSpsmn7ABEJQQwTFEYgjl394Tz5eHw0jlM/WEoYUYxqlm9zBKIC5xhjUpYAQhD4URjC//Capun7YZ5mwSomBeaF67pIl2+nRDDO+wOrOxhH/4o551q3dhybWgstS0XiKAJ3wCRZrVbDvP/2/efN+8/rtX+2u4cTi53ZzdPixLXRRUVcnotxguDa97uuuf34hT67iYK1swP39B4Xwpidi12rRnW1mxz4QXhh5VaAWZJhTGlWogRFURgH/l/itjWDtUrWvJYus5LSdKbr2upxbiY9nCp73dpTsxyHbliQ3oMovOzvCVG5g1lrGeFMiaIqOePyDt4TLGTW0VzgTCJMMlxSWDB3+bIsKaW/AXI5a9Zytj4fAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"vscodevim\"\n        title=\"vscodevim\"\n        src=\"/static/a0451de7e507bc1cc62ee189d3ff81a6/78a22/vscodevim.png\"\n        srcset=\"/static/a0451de7e507bc1cc62ee189d3ff81a6/78a22/vscodevim.png 585w\"\n        sizes=\"(max-width: 585px) 100vw, 585px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Here's how my vim setup looks.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 66.61538461538463%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACcklEQVQoz03R527qMBgG4Aha0pDJyLITZxOy9yBA2KK0PTq9/6s5of1zpEeWLL2v7M/GHKZTJrE09sBrII7WM8weLF9XyjTVqFwhYvkt4H/hgUCE/KsnTDwB912+xUJ0tPgcUv5/AkCF+rx2+c5ZNCZboEWF5qVKxzqXaVwGyUgmgkQ7YLV/i4xeIkIwjQD5KwZUotKlzjU6WwMqU+hcoQuVKUU8Wo68xcjjX7wQ7oeTT/qsWY5jYZKJeC7ihYSXMln46jWz31PrPbUfProG6ObKJ43bCJN0IE7iEB4wSDWAaiC9QdxeWxwGaN4jvg+0j1S/h+o11u+J9RmbD0+5ONJRZbshD8gmUs/YEFW4ncJtdeFsiFddPKnzPeJ3K/VugZMp9ZZ6cc2Hb/1x0YfGH+Gz3CpMF6PbUN4jpkVUrXEdmm9VtgVkOUxogE5TayRUJtxY6OAYF1M4ILaFZAXJWqHqWL1gw0YjK2P6XBFVaQOyNLlqzffrWecvdxZT6WRh0tWP0mSG998MsQgeMZmo0LQ2qcakW5NprafGYptUvbX2o7EetX1PleN63ppkYRC5TlY61SKicpcdpjONzW5crltxncNuhqZOlhpV+PKxMG8pOufaJYPnHJxCePLB0XxerUFEiaY55s6aFdvYVK1PC4hn8iQRxrGEx4hqlLdSHIdLzBdHgfRDHoXgJQSTRH6JeGyNrZcHe7Y32C2iu+HDAJnL0wSxVaJ9psZHhK6JcYjUXahsI2Ubwn41722mX7EHh9lhufMdaV8B+jT5q7E4abMScanDD7mvNbj78OqB1pVqRyhcsfTBLgDvGfibw+9U+voHI5Bsu60nJMIAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Vim\"\n        title=\"Vim\"\n        src=\"/static/dde8da85e3217326808f870a6728802d/e5715/Vim.png\"\n        srcset=\"/static/dde8da85e3217326808f870a6728802d/a6d36/Vim.png 650w,\n/static/dde8da85e3217326808f870a6728802d/e5715/Vim.png 768w,\n/static/dde8da85e3217326808f870a6728802d/c1b63/Vim.png 1200w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Now go give it a try. I wish you luck!!</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"title":"Vim: What is it and Why to use it?","author":{"id":"Shubhankar Khare","github":"iamshubhankarkhare","avatar":null},"date":"October 08, 2020","updated_date":null,"tags":["Vim","Text Editor"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/dde8da85e3217326808f870a6728802d/ee604/Vim.png","srcSet":"/static/dde8da85e3217326808f870a6728802d/69585/Vim.png 200w,\n/static/dde8da85e3217326808f870a6728802d/497c6/Vim.png 400w,\n/static/dde8da85e3217326808f870a6728802d/ee604/Vim.png 800w,\n/static/dde8da85e3217326808f870a6728802d/f3583/Vim.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"fields":{"authorId":"Shubhankar Khare","slug":"/engineering/vim-getting-started/"}}}]},"authorYaml":{"id":"Shubhankar Khare","bio":"He is a passionate full stack web developer from India. He loves learning new technologies and is an open source enthusiast.","github":"iamshubhankarkhare","stackoverflow":null,"linkedin":"shubhankar-khare","medium":null,"twitter":null,"avatar":null}},"pageContext":{"id":"Shubhankar Khare","__params":{"id":"shubhankar-khare"}}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}