Pull to refresh

Modes are vim’s killer feature? Seriously?

Reading time 5 min
Views 2.7K
Original author: @varanio
Author of the original post in Russian: varanio

You may have read a recent article suggesting that vim is great unlike IDEs, because of their allegedly low typing speed.

Let’s recall that the main message of that article was that vim’s killer feature consists in its modes that sort of outshine everything else. That said, the author acknowledged that IntelliJ IDEA and other IDEs provide hotkeys and other user experience which can be easily used. However, since they lack modes, vim is supposed to be everyone’s first choice.

The author then suggests that instead of pressing ctrl+arrows to move between words, it is easier to press Esc, e and then go back to the i editing mode. Understandably, all this trouble because the author finds it inconvenient to hold ctrl.

I know that articles that criticize vim get many negative votes, but I just have to speak out.

Are your lines of code so long that your finger grows tired holding the key to the point where you really need modes? I can get it when you are typing a long constant — in this case you can press Caps Lock and type its name. Even then I hardly press this key more often than once a year. But to switch modes back and forth for moving forward down a couple of words, let alone to call that vim’s killer feature, sounds like a bit of a stretch.

By the way, in IntelliJ IDEA, you can change the case of a word (or the selected text) with one key, so it does not really require using Caps Lock either.

I admit that vim can be good for editing config files on a remote server. Also, vim can be great for new languages that have not yet been played around with by JetBrains. Writing custom plugins is easier for vim (but in 99% of cases you won’t need them with an adequate IDE). Perhaps, it is more convenient for editing long texts. But that is irrelevant for standard industrial coding!

I should at once mention several points here.

Vim can be turned into a kind of IDE by installing plugins and learning hotkeys to operate those plugins


It can indeed, but why would anyone bother?

It seems like a weird challenge considering that IDEs have it all, and with a much more user-friendly experience. You won’t have to use a mouse, I promise!

Let me explain the thing with editing without a mouse by using an example. I first open IntelliJ IDEA and create a new file.

I press p, and the IDE immediately prompts me with a suggestion of the word package. All I need to do is press Enter to put the word package into the text inside the editor.

Then I press c, and the IDE suggests class at once.

I enter the name of the class (e.g., Habr), type the curly brace {, and the IDE automatically completes the closing brace just behind the cursor.

Then I type pu, and the IDE understands that it’s probably public. I type in H and press Enter to get Habr, because the IDE has already got it that I want to create a constructor.

I proceed to writing the body of the constructor, e.g. I call the init() method, which is not there yet. My IDE highlights it with red color, which indicates that this method does not exist. Once I press alt-ENTER, the IDE will insert the code snippet in the right place:

    private void init() {
    }

If I happen to type new Habr(5) inside this method (the word Habr was also prompted of course), i.e. if I try to call a non-existing constructor, IntelliJ IDEA will underscore that bit right away, so I just press <alt-ENTER> and choose what exactly I want to do: whether it is to add an int argument to the constructor or add a new constructor with an int parameter. I choose the latter option, and the IDE immediately adds a new constructor after the first one:

public Habr(int i) {
}

I won’t mention the automated indentation and other features that help you edit the code, since naturally they are present.

Here is what I got in the end:

package x;

class Habr
{
    public Habr()
    {
        init();
    }

    public Habr(int i) {

    }

    private void init() {
        new Habr(5);
    }
}

All I did was literally hit a couple of keys and the <alt-ENTER> hotkey.
I did not install any plugins.
I did not have to train for a month to be able to do this.

I NEVER TOUCHED THE MOUSE (I used Caps Lock here not because I wanted to shout out like a nutcase, but because it was fun to try the feature).

I did not switch to any modes and did not have to recall any key or knob combinations. The only one I used was <alt-ENTER> (but that was a context-dependent thing, a sort of a “problem solving” hotkey).

If you hate using the mouse, you can navigate through the code using special hotkeys, such as for jumping to the right class, file, method, line number, etc.

You can select text by repeatedly pressing <ctrl-W> to select the current word, the current text between the braces, etc.

Vim allows you to jump to a particular character. For example, you can get to a letter x in the line of text without touching the mouse. Yet an IDE also gives you this opportunity through pressing <ctrl-f> and typing in the required chunk of text. This is also a sort of a mode by the way. It is called the search mode, duh!

I also don’t need the mouse to jump to the right function call and then, again without the mouse (press ctrl-b), to jump to the description of this function.

Vim has several unique out-of-box editing features that are missing in IDEs


  • Move to the next/previous paragraph.
    Yes, it sounds like a useful feature for an IDE. But rather for editing articles for Habr than for actual coding.
  • Move to the next space character.
    Well, you can call it a useful feature, but not too cool. The repeated pressing of ctrl+arrows will produce the same effect.
  • Jump half a page up/down.
    I haven’t yet decided whether I need this one for anything.
  • Jumping to the first/last/middle line on the screen.
    I don’t really see what this is for. That is, it may come handy some time, but it is by no means a killer feature.
  • It is possible to delete exactly N lines of code.
    Yeah, right, I do this every day. Everybody needs to delete exactly 19 lines of code from time to time, right?

I am in no way a vim guru, so I may have missed some key aspects. Please share your thoughts in the comment section. Yes, of course there are zillions of plugins on top of that. But IDEs also have them, and in comparable quantities.

Summary


Here is my own take-away from this. I will stay away from vim when it comes to code editing, no matter what you’ll say. I was not very impressed with using modes instead of holding ctrl or even ctrl-alt-shift. IDEs give you more out-of-box features, without the need to spend a while on learning and assigning hotkeys. Most everyday tasks can be accomplished with an IDE by learning just a couple of hotkeys. You can even skip them altogether if you are happy using the mouse.

It has long been established that a programmer takes more time to learn code than to actually write it. So whether you’ll use your mouse or not does not make big difference. However, let me reiterate that IDEs allows you to do almost everything (if not everything) without using the mouse.

Vim will work better than nano for remotely editing config files on a server, provided that the following conditions are satisfied:

  1. You need to have a good grip of vim.
  2. You need to edit industrial quantities of config files to feel the advantage. If you only need to make changes to one configuration file once or twice a month, nano or indeed anything at all will work well.

You can start voting me down or, better still, offering your counter-arguments :).
Tags:
Hubs:
If this publication inspired you and you want to support the author, do not hesitate to click on the button
+15
Comments 6
Comments Comments 6

Articles