VIM - the Best Editor for Everyone

Posted in editors minimalist linux -

In this blog, so far I have talked about minimal software, about command line interface, and most importantly, about how not using your mouse is good for productivity. cased those “principles” that (I hope) we’ve come to an agree, now is the time to discuss something more practical, starting with: what text editor we should use? In this post, I want to introduce to you a little bit about one of the best options you can go with: VIM.

If you are a developer, I bet you have heard of VIM (and if you have not, I’m happy to be the first one who mentioned it to you). It’s quite a popular choice of text editor in the programmers community, due to some of the characteristics that we all love: lightweight, fast and reliable. However, the fact that not everyone is using VIM also has a reason: it is quite difficult to get started with, and its behaviors are quite unexpected (or even a bit weird) for those who are not familiar. (Apparently, “how to exit VIM?” is quite a challenge for many people, and even became a quite funny joke. Trust me, once you know enough about VIM to move around freely in it, you’ll find the joke funny). So in this post, I’m gonna discuss some pros and cons of VIM, and share some of my experience to cope with the cons and keep loving the pros.

Pro 1: VIM is fast and doesn’t need mouse

The first thing that I bet every long-term VIM user loves about VIM is how fast it is. By “fast”, I don’t purely mean that VIM’s light weight and runs smoothly for even giant files with thousands of lines, but also about how convenient it is to do exactly what you want with it. Built from Vi editor, which was developed long before graphical interface or mouse even existed, VIM (which stands for “Vi IMproved”) was built around the keyboard, and is a very powerful editor that way.

In fact, VIM producers even considered using the arrow keys a waste of time (and of course they were right, if you look at the distance between the home-row (the asdf.. row) and the arrow keys in your keyboard), so every activity in VIM is designed to be using keys closed to the home-row, which allows you to freely do everything without the need of moving your wrists to another positions (so it’ll just be like when you’re typing: you mostly move your fingers, and with it your hands may move slightly, but the wrists will stay still, which is very time saving and also good for ergonomics).

This post is not intended to be your first VIM tutorials, but just in case you’re wondering: you can use the keys “h”, “j”, “k” and “l” to replace “left”, “down”, “up”, and “right” (not that the normal arrow keys won’t work, but as said, it’s much faster this way). And before I forget, VIM has several modes, of which the most important ones are called NORMAL mode (in which the letter keys are use to give commands to VIM, which means you can’t type anything) and INSERT mode (which, as the name suggests, is for typing). To move from NORMAL to INSERT mode, you press “i” (for insert), while to move from INSERT mode (or any mode but NORMAL) to NORMAL, you just need to press ESC key.

Tips: Since the ESC key is quite commonly-used in VIM, it’ll be a good idea to map it to something closer to the home-row. Most VIM users like to map it to either “jj” or “jk”. I personally choose “jk”, so that even if I mess up and press it while I’m in NORMAL mode, it’ll do nothing unexpected (In NORMAL mode, “jk” just means go down and up again).

While those basic knowledge about movements and MODES are enough for you to start exploring VIM, the best thing about it is that there are always things to improve your already-fast speed. Later on, you’ll find out that there are always several ways to do the same thing in VIM, and you can do things faster if you can learn a faster way, which means your speed will improve even more as you get more experience.

Another benefits of learning VIM is that you can apply similar keystrokes in several places that normally require the use of mouse, like web browsing (You can do it right now with your favorite browser, using this extension in Chrome, which can also be installed in all browsers which use Chromium core. The same extension can also be found in Firefox).

Pro 2: VIM runs everywhere

The best thing I like about VIM is that you can find it installed everywhere, so pretty damn handy. When you are accessing a remote server (which normally runs Linux) and suddenly need to edit a text file, you can almost always find VIM (or at least Vi) installed there. VIM is also installed as a default in MacOS, and can be installed in Windows, too.

The fact that VIM can be installed anywhere proves how lightweight VIM is. Even if your computer is 10 years old or more, VIM can still run smoothly. It’s handled worse situations than that.

In most tutorials you find online about setting up a remote server, you will likely see the instructors using Nano, another light-weight editor that is widely installed by default in several Linux distributions. Feel free to change the command from “nano” to “vim” in those situations.

Pro 3: VIM is customizable

Of course, all the text editors, more or less, allow users to customize here and there, but the good point about VIM is that you don’t have to do those changes using graphical interface, which means if you buy a new computer, you won’t have to customize VIM again to make it work as your old one. Instead, every customization in VIM is made using a configuration file, so all you need to do is to copy that file to your new computer, and it will work just as if you have spent several hours configuring it.

Several more “modern” editors tend to replace config file with an Export/Import config function, in which you can export changes you have done to your system to a file, and then Import it again to a new computer. While it solves the problem of repeating, those export files are normally hard to read (as they are generated by the software), so it will be hard to copy a part of it, for example to copy a particular change from someone else. Those auto-generated file is also bloated and changing all the time, which makes version control for them a hard job.

So does VIM have any disadvantages?

Yes. But honestly, whether or not those things are cons depends on who you talk to. Rather, I think they should be mentioned as “reasons that some people might not like VIM”

Reason 1: VIM is hard to learn

Using VIM requires a lot of muscle memory, which doesn’t form up in one day. If you think about it, it’s kinda like the muscle memory you had to form when you learned how to type (I did that learning quite late, in secondary school, so I remember the experience vividly): When you first learn how to type: you had to remember the position of each key on the keyboard, and by what finger you should press it so that your speed is as high as possible; now with VIM you also need to remember which key to press when you want to do something. It’s quite a lot to absorb at once, and that’s why many people give up on learning VIM the moment they open it up (maybe that’s why so many searches for “How to quit VIM”).

Also like typing, after your muscle memory started to form, you won’t need to think about it anymore. I bet that as you type, you no longer stop and think of where your hands should be positioned next, do you? Instead, you focus on what sentence you want to type, or what ideas you would like to express. Your fingers just automatically move and the right words magically appear on your screen. Same goes to how VIM muscle memory is after it’s formed: you will think that you need to move down, up, to next word, to next paragraph and things just happen naturally.

So how do you cope with this learning curve? Well, just like learning anything, to learn it fast, you need to know some basic stuff, and keep playing with it until you get better (you may revisit my third point “Learn how to learn” in this post.

The best way to get started with VIM is by using vimtutor. If you are running MacOS or Linux, chance is you can just start up your terminal and type vimtutor (on Windows vimtutor should be in the same VIM that you have installed). Try going through the whole tutorial a couple of times, it will give you enough muscle memory to get started.

Reason 2: VIM doesn’t look good, and lack some of “modern” functionalities

It depends on your taste, but for many people, the look that a 50-year-old text editor provides isn’t a selling point. The good news is: you can actually config VIM to be anything you want. There are tons of custom-made plugins and configs that you can just put into your VIM config and adjust as you like, nobody’s holding you back. Whether you want to make your VIM into a lighter-weight VSCODE, or Sublime text, or a combination of two, you’ll get it. In fact, for most people, it’s gonna be a never-ending process of adding and removing things from the config. The sky is the limit for your creativeness.

How to make those creative configuration is another story, which will likely take us several more posts. Let’s leave it for next time then.

Stay tune!

Written by Huy Mai