Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using Vimgolf as a bit of professional development.

In this particular task One of the best solutions is the following command.

<C-V>Gg?ZZ

I understand ZZ is to save and exit - and that control-v is entering visual mode, but the Gg? looks like sorcery for me.

Google is letting me down a little bit with the search - not least becaues it appears ? is overloaded in both Google and vim... Can someone pick this apart for me? g? on any given line in vim looks like it rotates characters though some sequence... :s

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

The task is to rot13 the first column of letters so that they match the word after for; from there it's rather obvious that the top solutions perform the equivalent of a rot13 in one way or another. If we leave out everything we know that is unrelated to rot13 or, at least, changing text… what are we left with?

Let's break the command in smaller chunks:

(<C-V>)(G)(g?)(ZZ)
  • \1 is visual-block mode, nothing to do with rot13 or changing text.

  • \2 extends the visual-block selection to the last line of the buffer, again, nothing to do with rot13 or changing text.

  • \3 is… what?

  • \4 writes and closes the buffer, again, nothing to do with rot13 or changing text.

After all that, g? (the remaining chunk) is the only part of this command that we don't know and that could have something to do with changing text or, maybe, rot13. Given the high rank of the solution and the unbelievable terseness of g?, the probabilities that it does precisely what is asked, rot13, are very high.

Or is it?

To make sure that we are on the right track, let's ask Vim:

:h g?

to which Vim responds, in its usual voice:

Rot13 encode {motion} text.

No google, no internet. Only grey matter and Vim; the unbeatable duo!

share|improve this answer
add comment

G means "go to the last line". So if you're at the beginning of the file and press

<C-V>G

you end up marking the first column of every line. Now

g?

means do a rot13 encryption. This consists of rotating letters 13 points down the alphabet. This extremely weak encryption is used in online forums to hide offensive language, spoilers, and other stuff you don't want people to read unless they realy want to.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.