How can vim make you a better developer
Tags: editor, vim, productivity, linux
Published: 2018-04-09 06:44:28

---
title: How can vim make you a better developer
published: true
description: 
tags: editor, vim, productivity, linux
cover_image: http://pmihaylov.com/wp-content/uploads/2018/04/Selection_016.png
canonical_url: https://pmihaylov.com/vim-better-developer/
---

The first time I encountered vim was during a Linux System Administrator course I attended a while ago.

Didn't really know much about Linux back then. It just sounded quite fancy.

During the course, the lecturer often typed in that 3 word command <code>vim</code> and edited some stuff.

"Gee, that looks cool", I thought!

So, determined to look cool myself, I got back home, opened a terminal, typed in the magic words and voila! - I was inside vim.

So, with a great wish to write my first <code>Hello World</code> txt file in vim, I started hitting keys on my keyboard. And nothing was happening.

Some strange beeps started coming out of nowhere and I felt utterly frustrated!

So, my goal quickly shifted from typing anything, to exiting <code>vim</code>. Yeah, you probably know what follows.

A key-hitting berserk got me while doing everything I can to exit <code>vim</code>. Finally, after failing my first clash with the editor, I was so thankful to have the X key at the top right of my terminal emulator.

Now, this story should sound pretty familiar if you ever tried using <code>vim</code>. Well, eventually you learn how to exit it, and you learn how to type in symbols.

But there is so much more to it. The endless sets of key-combos can leave you wondering what the heck you did after accidentally hitting a key.

Nowadays, <code>vim</code> is the most popular text editor out there. Even some Windows users tend to use it although being an indigenous Unix utility.

But what's the point? There are so many IDEs out there. Why would anyone bother poisoning his life with an endless vim frustration, when he can just install the first Javascript IDE google suggests.

Well, although it is probably not suitable for any project, there are some great benefits in sticking with vim at least for a while.

The greatest one being the user interface. However, the focus of this article is not that. Many articles can be found on the subject and perhaps I will make one in the future.

Today, we will explore the much less highlighted merits of the vim editor.

<!--more-->
<div title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq"></div>
<h1 style="text-align: center;" title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Curing the IDE illness</h1>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">The IDE is a great tool. It gives you some pretty cool features on the get go - auto-completion, code templates, code snippets, etc.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">These things are irreplaceable, especially for big projects. But they can also greatly cripple the skills of programmers who have never used anything else. The reason is that by using such utilities, you become sloppy in your writing, because that function call is one tab away from auto-completion. Also, you might be surprised what gaps you might have developed in your knowledge due to these tools.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">I am such an example. There were two instances when I was amazed by my short-comings due to the <strong>IDE illness</strong>.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">One time, I was an assistant during a programming course and one guy asked me for help in one of the first lectures of a programming basics course. He had created a new VS template with a <code>Hello World</code> C# program, but he had messed up the initial C# code and it wasn't compiling.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">So, he was asking for assistance to get that fixed. I tried doing that, but then I was amazed that even <strong>I didn't know how to write a basic C# Hello World program without relying on the standard template</strong>. In the end, I told him to delete the project and make the new one, so that VS creates the <code>Hello World</code> template for him.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">That came as a great surprise to me. I was so used to the default Visual Studio C# template, that I wasn't able to write it myself.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Another such instance was when I tried to write a for loop without using auto-completion, the first time I tried vim. <strong>I couldn't do it</strong>. I didn't know what went where in the loop declaration because <strong>I had always used auto-completion to write the for loop for me</strong>.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Now, you might think that happened very early on in my programming experience, but you are wrong. I had already learnt what OOP is, several programming languages and some basic data structures. <strong>I had been programming for nearly a year and yet, I was unable to write a for loop on my own</strong>.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">With a basic vim, you don't have auto-completion and default templates. This way, I was able to detect these shortcomings and amend them.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">And what's more, being required to write the whole function names on my own, I was able to become an extremely fast writer. Now, I feel the keyboard as a continuation of my hand.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">That doesn't mean I don't use auto-completion and templates in my projects, though. I do use them, even with vim (when I set up some plugins). They are great tools that greatly increase productivity. But I believe one should spend some time creating projects without these utilities in order to feel the gritty experience of writing the entire code on your own.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">This will definitely make you a better developer. What's more, many companies use whiteboard interviews to test their candidates. If you are unable to write a hello world program without auto-completion, all your algorithms knowledge won't help you on the whiteboard.</p>

<h1 style="text-align: center;" title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Removing the layers of abstraction</h1>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">When using an IDE, everything is one-click away. You can compile, link and run your project by clicking <code>Ctrl-F5</code>.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">In reality, those are three different commands.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">From time to time, you can spot a loading bar in the bottom of your IDE, with a status message <code>Indexing</code>.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Do you know what that is?
Why is it done?</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">And did you know that in order to build your project, the IDE uses a configuration file, that outlines how the individual files are to be compiled, linked, how to run the tests, etc?</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">The exact application of the configuration file is project-specific, of course, but it is possible to configure all these properties.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">If you don't use an IDE, you have to write this configuration file on your own or generate it explicitly (Makefiles are example of this in C/C++ projects).</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">And by using an IDE, these details are hidden which saves time, of course, but leaves you with a lack of knowledge again. Some might say that you don't need this knowledge if you don't encounter it in your day-to-day job.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Car mechanics can get away with not knowing how the engine works if they are only substituting car parts in their job. Does that make them masters of their craft?</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">But by using vim and the terminal, all these intricacies are not hidden from you and you have to explicitly do them. This takes more time to an apprentice, but lets you explore the capabilities of your system.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">For example, did you know there are compiler options, different from your IDE defaults?</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">Another thing is that using this approach makes your project more portable as you are using universal tools, not IDE specific ones. One problem I have encountered with this in my experience was a very old project, which was required to be ported to a different IDE.</p>
<p title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq">I had to delve deep into VS specific configuration files in order to reverse-engineer the build system of my project. By using a Makefile, for example, you can simply import a Makefile Project in any modern IDE and you have your project ported out of the box.</p>

<h1 style="text-align: center;" title="MDH:cyAqKjMga2V5c3Ryb2tlcyoq"> An Ocean of IDEs</h1>
For C#, you have Visual Studio. For Java, there is Eclipse and IntelliJ. Python has PyCharm. And there's C++'s Code Blocks.

Even if you stick with a single language, there is a chance you will still have to switch IDEs between projects you work on.

So why is this a problem?

Well, by constantly switching tools, you have to go through learning that IDEs shortcuts and key bindings. Many don't even bother and go on using the mouse and click click click.

That means that your productivity won't be as high.

Also, running an IDE is tough on your laptop. I have had instances of having CLion open for a C project, IntelliJ for Java and PyCharm for Python.

If you have an old laptop, like me, then that won't be a pleasurable experience.

But even so, I am bothered with having to use different tools for different languages. Every tool has its own intricacies and shortcuts.

Having to IDE switch all the time, leaves you with using only the least common denominator utilities of each IDE because you can't learn them all.

By using vim, you have one editor to rule them all. And you have the same shortcuts and key bindings on different languages.

But using vim can be bothersome on some projects, though. For example, C# projects are pretty coupled with Visual Studio and you will have a hard time if you try substituting VS for vim. However, what you can do instead is use a <a href="https://marketplace.visualstudio.com/items?itemName=JaredParMSFT.VsVim">Visual Studio plugin</a> to emulate vim inside VS. That way, you can have your favorite shortcuts inside your preferred IDE.

A similar plugin is available for the other major IDEs as well.
<h1 style="text-align: center;">vim can get fancy as well</h1>
Using bare bones vim is beneficial as outlined in the "Curing the IDE illness" section. But for big projects, I'm a fan of using plugins to match IDE-like behavior simply because navigating a code base can be much easier.

This is a screenshot of my custom tuning of vim:

<img class="alignnone wp-image-683" src="http://pmihaylov.com/wp-content/uploads/2018/04/Selection_012-1024x538.png" alt="" width="821" height="431" />

It has many great features and using it, I was able to entirely substitute CLion for a quite big C code base.

In a new series of articles, I will start exploring my favorite vim plugins and explaining when they are useful and when they are not.

But if you'd like to have an IDE-like vim, you can clone my <a href="https://github.com/PreslavMihaylov/dotfiles">dotfiles repo</a> and run the install.sh script. It will configure the exact vim configuration I use now.

Note that there are some non-vim related configurations in there, but you can easily extract the relevant things. I have left comments explaining what each part of the script does.
<h1 style="text-align: center;">Conclusion</h1>
Apart from vim's lovely user interface, there are other benefits to using it at least for a while. If you're too used to your IDE's code templates and auto-completion, it's time to give vim a try. Be warned, IDE illness is not to be taken lightly.

Furthermore, if you'd like to take a sneak peak behind the abstraction the IDE provides you with, it's time to open the terminal and create a project using vim from scratch. You might not like the editor, but the knowledge you will gain is priceless.

And if you are sick of using 5 different IDEs for doing your job, vim can be the right option as well. It grants you a single set of tools, portable for different projects.

So what are you waiting for?

<code>sudo apt install vim</code> and start your journey with this great editor.

Once you do that, whether you like the editor or not, it will make you a better developer.