Why you should consider learning Vim?

Why you should consider learning Vim?

Why learn vim?

Before we jump straight to the answer, let me ask you another question. How many times do you change a piece of code, refactor, correct typo errors, etc? I am sure the list doesn't stop there, there are heaps of examples you can add!

And for every little change, be it changing a letter, you will need to do numerous pesky movements like setting up the cursor to a position using your mouse and then replacing that letter. As one of my grumpy coworkers would always say "Arrrrrrr…rrr!!!!”.

However, using Vim you will edit your document with ease without having to lift your hands off the keyboard. Impressive right? See the following example.

abi8sp273ht53k60s5fh.gif

So what is Vim?

Let me put it in a more straightforward way, "Vim is simply a text editor that lets you use shortcuts to manipulate text."

Did you buy into why you should learn Vim?

Ok, ok I get it, maybe you are not persuaded just yet. So let me start from the beginning, and share with you a story which I believe most of you might relate to.

In the old days when I started to learn programming I was like:

"Yeah, yeah I get it, I learn a for loop, an if statement, basics of programming and still I cannot put the hours in to harness that skill, there is something restricting me from committing to it, I wonder what and why that is?"

In this case it was not that I was finding programming difficult, it was totally the opposite, I had the hunger to learn more, but you know what, constantly using my mouse to do anything like scrolling up and down, changing things here and there were driving me crazy. They were preventing me from entering the so-called magical land, “the flow”, as programmers would describe it. This affected me to the point that I had no desire to write any code at all, nor being in front of my computer, programming. Then, I said to myself (like in a movie or inspirational speech).

giphy.gif

Yes, I said to myself, there should be a better way than this. And, I thought, hang on, there is that thing, what is it called again? Vim! An obscure thing, that most programmers are afraid to even try — or are warned that it is only used by the “10x programmer”.

Back to my monologue, I said, do you really want to do this?

As the question came through, I instantly replied back, if it is the only way, hell be it.

I guess, there is no need for me to continue, you already know the end of the story, I am happily enjoying each and every moment using Vim to the extent of using it to write this very post.

You are probably saying, “wait, you forgot to mention the most important point, how did it work out for you?”

This may sound weird, but I kind of feel one with my code. But, how, you wonder?

Let me explain.

Spending time switching from my keyboard and mouse, for a split second, stopped the logical thoughts that I may have had at the time I was looking at a piece of code. However, using Vim, I focus on problem-solving and worry less about making changes which are by now second nature. In addition, due to how easy it has become to edit a document, there has been a tremendous improvement in readability and maintainability from my past implementation compared to now, as I tend to refactor and clean up more.

Now, of course, it takes time to learn and memorize the shortcuts, but I guarantee that once you have them down, your productivity will be through the roof!

It’s about time to take a deep dive in Vim. But, before I do, let me clear out the "stigma" that certain vim users have repeated so often that everyone thinks it is the truth. “Vim users should only use the terminal and commands”.

giphy2.gif

Hell no! Until you reach the point that you are an expert, the only thing you need to know to get started is to install the Vim plugin to your favourite editor or IDE and you are good to go. This will spare you the burden of setting up Vim and instead, help you learn the commands progressively until you are comfortable with it. Treat it like the training wheel at the back of your bicycle.

Finally, we have arrived at the fundamental part that will allow you to apply Vim in your day to day tasks.

There are different modes in vims, three of those that you need to know are: normal mode, insert mode, visual mode.

Normal mode is used to navigate your document and it can be accessed by pressing the key.

Insert mode, as its name describes, is used when you need to enter text in your text editor.

Visual mode handles the selection of text within the editor.

I think this is a lot to digest at once, so I will keep the essential vim commands that you need to know in my next post. In the meantime, I will provide you with some resources that you may find useful.

Vimtutor which you can download from www2.geog.ucl.ac.uk/~plewis/teachi... and start practising using vim in your editor, I like to use VsCode. The main area you need to focus on there is navigating through a document using h, j, k and l.

Here is a Vim Cheat Sheet (rumorscity.com/wp-content/uploads/2014/08/1..), instead of me going through each command one by one, this picture sums them all up, and is easy to refer to, each time you forget how to do things.