Vim Golf (text-editing game)

Is anyone here into Vim? It’s an advanced text editor that has keybindings for just about any action you want to perform.

There’s a Vim-based game that might interest people. You have to figure out how to edit some text with the fewest number of keystrokes possible.

Here’s a link:

An example challenge from the site is to transpose this matrix:

((1, 2, 3, 4),
 (5, 6, 7, 8),
 (9, 10, 11, 12),
 (13, 14, 15, 16))

The result should look like this:

((1, 5, 9, 13),
 (2, 6, 10, 14),
 (3, 7, 11, 15),
 (4, 8, 12, 16))

It looks like the current record is 23 keystrokes (no mouse).

that’s easy… it’s simply two characters:


1 Like

Doesn’t that just run a shell command?

(I’ve been using Vim for 15+ years and still haven’t found many of the features.)

Those two by themselves actually run the last command in your history. So if you got a C++ (or whatever you prefer) program that takes care of transposing the matrix, make sure you run that program, and then just repeat it with :! from within vim.

Btw, that’s the answer to any vim in the fewest keystrokes problems… unless the task is to delete a character, which can be done by just typing a single ‘x’-character. It’s not really cheating* considering the way the question was phrased.

*whoever thinks this is cheating, doesn’t understand what “thinking outside the box” really means. :wink:

1 Like

I’ll have to read up on it. I tried it but it just said [No write since last change]. It’s doing something, but I’m not sure what. (My last !-command was pandoc and my last shell command was ll.)

I’m using Neovim in zsh though, so maybe it’s a little different. There are a few Vim things that don’t work exactly the same in Neovim.

I don’t have that environment available to check for you, but try:

:! wc %

…and see what that gets you. It’s not the two-character-solution, but if that gets you the word count for the current file, then you can just replace “wc” with any other program that you want to send “%” into. Still better than…

To paraphrase Spoon-boy from from the Matrix:

Spoon boy: Do not try and bend the spoon be outside the box. That’s impossible. Instead… only try to realize the truth.
Neo: What truth?
Spoon boy: There is no spoon box

1 Like

Ah, I see now. I usually do that in visual mode.

Select all:


Run command on selected text:

:!pandoc -f markdown -t html

Or g followed by ctrl+g to save 6 keystrokes. :smiley:

There are a couple of related stories in the Vim Koans.

1 Like