DEV Community

Cover image for How can vim make you a better developer
Preslav Mihaylov
Preslav Mihaylov

Posted on • Updated on • Originally published at pmihaylov.com

How can vim make you a 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 vim 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 Hello World 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 vim. Yeah, you probably know what follows.

A key-hitting berserk got me while doing everything I can to exit vim. 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 vim. 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, vim 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.

Curing the IDE illness

The IDE is a great tool. It gives you some pretty cool features on the get go - auto-completion, code templates, code snippets, etc.

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.

I am such an example. There were two instances when I was amazed by my short-comings due to the IDE illness.

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 Hello World C# program, but he had messed up the initial C# code and it wasn't compiling.

So, he was asking for assistance to get that fixed. I tried doing that, but then I was amazed that even I didn't know how to write a basic C# Hello World program without relying on the standard template. In the end, I told him to delete the project and make the new one, so that VS creates the Hello World template for him.

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.

Another such instance was when I tried to write a for loop without using auto-completion, the first time I tried vim. I couldn't do it. I didn't know what went where in the loop declaration because I had always used auto-completion to write the for loop for me.

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. I had been programming for nearly a year and yet, I was unable to write a for loop on my own.

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.

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.

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.

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.

Removing the layers of abstraction

When using an IDE, everything is one-click away. You can compile, link and run your project by clicking Ctrl-F5.

In reality, those are three different commands.

From time to time, you can spot a loading bar in the bottom of your IDE, with a status message Indexing.

Do you know what that is? Why is it done?

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?

The exact application of the configuration file is project-specific, of course, but it is possible to configure all these properties.

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).

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.

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?

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.

For example, did you know there are compiler options, different from your IDE defaults?

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.

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.

 An Ocean of IDEs

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 Visual Studio plugin 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.

vim can get fancy as well

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:

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 dotfiles repo 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.

Conclusion

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?

sudo apt install vim 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.

Latest comments (7)

Collapse
 
geoffmcnamara profile image
Geoff McNamara

Learning to use vim comes in quantum packets. Big jumps occur over time frames. Once you start to manipulate your own .vimrc file a quantum jump occurs. Then another with plugins. Then it all seems to get muddled. I came across fisa-vimrc which automatically loaded some of the best plugins. With a little tweaking ( see: http:companionway.net/post/control_vim_and_plugins) another quantum jump. Productivity increases with each jump.

Collapse
 
wangonya profile image
Kelvin Wangonya

So... my WebStorm license is just about to expire 😅 couldn't have read this at a better time. All jokes aside though, it just hit me that I'm a victim of IDE illness. I used to use Vim in school when I used to code a bit of C, but since I turned to front-end web dev, I've been a slave to IDEs. Time to change that. Thanks for the great post 😊

Collapse
 
ferricoxide profile image
Thomas H Jones II

Ok, I gotta ask:

vim's lovely user interface

This is joke I missed, right? Like, there's <sarcasm> tags that didn't render properly on my page-view?

I've been using various incarnations of vi (the original vi, vile, elvis, vim and likely a few others) for the 30 years I've worked on UNIX and UNIX-like systems.. This has to be the first time, in all my years of using vi-like interfaces where I've seen someone refer to vi's interface as anything approaching "lovely". I mean, I don't know many serious vi-users who could put those words that close together — even in jest — without some part of their brains catching fire. =)

Collapse
 
rossijonas profile image
Jonas B. R.

Great article!

vim is such a useful tool, it doesn't dry your RAM and you can rely on it even if you need to work on old machines!

The most Hyped tools right now (a.k.a. VSCode) can be a panic if you have plugins installed or a machine with low resources.

I write quick tutorials for vim beginners, please consider to check and share:

medium.com/vim-drops

Cheers! ✌️👌

Collapse
 
rossijonas profile image
Jonas B. R.

Totally Agreed!

The learning proccess is what makes me more excited to use it and I never get bored of it. There's always new tricks, you can program scripts to better your workflow... You keep programming and learning it's language, this is the life of a programer!

After using Vim for a while, I decided to write quick tips and tutorials for Vim beginners, to help them deal with specific configs and get excited with tricks you can use.

You can check it on medium.com/vim-drops !

Cheers!✌️👨‍💻⌨️👩‍💻✌️

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

vim has been my go-to CLI text editor for a few years now, and I am always surprised how much I like it. Unfortunately, I haven't really been able to dedicate much time to mastering many of the more advanced keyboard commands, but I'll get there! I spend a lot of time working on servers, and vim is the only editor I use on that job.

While I can certainly second your concerns about the IDEs, that somehow didn't happen to me. I've always had a personality quirk that compels me to type everything out, and understand everything I type. Autocomplete didn't even enter into the equation for me until some time after I started coding, simply because I didn't like giving up the "control" of typing it out myself. It was an option, but I always ignored it. Even today, I use autocomplete sparingly, usually only to speed up typing names of member variables or functions.

I would owe a large part of my coding skill to this habit. I was a proficient coder in three major languages only a year into self-guided learning. I have the ability to learn new languages, libraries, and frameworks rapidly, with mere days or weeks separating me from beginning to proficient. While some of that is my natural ability, it wouldn't be even remotely possible if I weren't typing everything out the long way!

Now...as an aside, emacs will accomplish the same end as vim. If you find you hate the one, try the other. (There also exists a combination of the two, wherein you have the emacs environment with vim keybindings.) Personally, I really really dislike emacs, but that is purely personal preference.

Collapse
 
pmihaylov profile image
Preslav Mihaylov

Hey, thanks for reaching out Jason.

It's great to see that you were able to overcome the comfort auto-completion gives you.

And it's not that I am entirely against it. Just the comfort it brings you which leaves you with skill gaps. Nowadays, I use auto-complete but I have configured it to be triggered manually, instead of automatically offering me completions.

That way, I can still type out all the symbols of a for loop, while keeping the possibility to auto-complete a 5-word identifier.

But apart from auto-completion, there are other layers of abstraction the IDE gives you. That's why I believe using a bare bones editor at least for a while is beneficial.

As for emacs, you are totally right. You can get the same experience using it instead of vim. I'm just a fan of the latter. :P