Archive for the ‘Linux’ Category

h1

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 😛