One letter forward, two letters back

26 March, 2010

I have been learning to use Vim*.

Vim is a powerful tool whose purpose is to delete text. There are shortcuts for deleting, commands for deleting, even the cursor is optimised for deleting**. There are hidden shortcuts for deleting, so that if you forget for a moment that you are using Vim, the next thing you type will delete a swathe of text as a friendly reminder. I have never encountered an editor so hungry for the total destruction of everything I manage to type.

Now, this leaves us with a problem. It is said that an infinite number of monkeys, equipped with typewriters, would eventually type the complete works of Shakespeare****. I suspected that if you gave them Vim instead, they would be unable to produce more than a few characters before deleting them again.

To test this theory, I built a vim-fuzzer. It goes like this:

for every permutation of three characters*****:
   run vim
   have it open a file of a known length
   type the three characters
   save the file and close
   note the length of the resulting file

(Well, more or less. For speed, there’s one instance of Vim and the file is a pipe. Have a look if you’re interested.)

The results are as follows:

  • On average, typing three characters into this test file deleted 91 characters. (In other words, the monkeys don’t stand a chance.)
  • The most destructive commands: 6078 permutations (2.5% of them), such as ‘bbu’, deleted all 1343 characters in the test file.
  • The most creative command was ‘Y9p’, adding an extra 4024 characters.
  • (I didn’t get around to calculating Levenshtein distances. I have Things To Do; the prize for Most Disruptive Command will have to wait.)

Ah, tangents, why do you plague me so?

* Peer pressure is a dangerous thing.

** When the cursor is a thin line that goes between characters*** and you press delete, what happens? There are two options: delete to the left or to the right. Currently most of our keyboards have two keys to address this problem, Delete and Backspace. However, if your cursor is over an entire character, it’s straightforward: delete that character. The opposite is true for inserting text. I maintain that this is just another manifestation of this thing’s fundamental hatred for text, and nothing to do with the keyboard layouts of the time.

*** as is normal and civilised, thank you very much

**** details of thought experiment may vary

***** Three characters from [a-zA-Z0-9] is 238,382 combinations and took over an hour to run. If you want the results for four characters, you can run it yourself. Or do the sensible thing and work it out with Maths™ instead 😉 And yes, with those characters you can’t access large amounts of the things Vim can do, but I already accidentally printed out about a tree’s worth of lorem ipsum and I’m not going to fuzz on :! even as user nobody 😛


  1. Vim certainly used to be a powerful tool. It did a cracking job of removing “indelible” stains from sinks. e.g. those left by students changing gearboxes. Sadly it now seems to have been banned by the EU as a potential weapon of mass destruction.

    P.S. I am informed that we recently managed to procure a quantity of this substance from a little known international arms dealer (Tesco). We await a pre-dawn raid from the local SWAT team ….

    • That’d be the *other* Vim. Also used for deleting things, though.

  2. Are you sure you are “learning” Vim? It sounds more like you are digging your heels in to resist learning it. Do you understand, or even __want__ to understand its input model? It sounds like you are trying to type text in the wrong mode and have no understanding that there is a “typing” mode and a “command” mode, and don’t understand why that would be the case.

    There are countless dozens of other editors that work just like Notepad for entering text into a file. They all use various combinations of control key and alternate key combinations to enter commands. Each was developed to correct the shortcomings in editors with similar command sets. And each has failed to gain traction with users. The frustration that spurs their development is not alleviated by the next new editor to come along. If it was, at least one of those editors would have gained popular dominance by now. Few editors that use Vim’s input model have been developed. Yet, they consistently score head and shoulders above other editors in popularity.

    As you so effectively demonstrated, novices are not able to cope with its interface. Vim’s interface was not designed for ease of use by novices. It was developed for efficiency and power after some degree of mastery.

    “I maintain that this is just another manifestation of this thing’s fundamental hatred for text, and nothing to do with the keyboard layouts of the time.”

    There is a clue in that statement about your fundamental attitude toward Vim and other vi editors. You think of it as outdated. I maintain that the usual CUA-compliant user interface for editing text used by other editors and by word processors is a failure. It is an unrecognized source of frustration to users who intuitively know that it holds them back and that there must be a better, more powerful way of editing. Unfortunately, users continue to seek relief for their frustration from the same type of editors.

    User interfaces may be easy to learn or they may be powerful. But the easier an interface is, the more power must be sacrificed to make that so. Vim Sacrifices ease of learning in favor of power. But it rewards the persistent.

    • Nope, definitely learning. It may amuse you to know that I used Vim to write the fuzz script, and please note that I didn’t say I don’t *like* it 😉 In fact, I learned a lot about the capabilities of Vim (and Python and pipes and users) along the way.

      I’m well aware of the various modes. If you look at the script you’ll see the mappings I used to prevent the fuzzer sending Vim into Ex mode, partly because of the potential for chaos (:ha, :sh etc) but mostly because Ex mode differs from the others in that Esc will not get you back to command mode, and handling that case was more effort than I cared to expend on this toy.

      This project is tongue-in-cheek, borne of the frustration you will always find at the bottom of a learning curve. Yes, I’m still a novice, and because of that I make lots of mistakes, mangle my text, do things in the wrong mode, delete when I mean to write, and would currently be able to produce the whole thing much faster in gedit where I know what I’m doing. But I see the purpose and the benefits of Vim, and I am persisting 🙂

      In short, don’t assume that just because I’m having fun abusing Vim, I’m not willing to learn to use it properly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: