vimrot13

What functionality does the "g?" command provide in vim


As a beginner programmer I've been practicing vim on vimgolf recently and saw that the command "g?" was used effectively to switch many lines of 'Ivm' to become 'Vim'. I understand that this shifts each alphabetical letter 13 times to the right but do not understand how this would prove useful except in unique circumstances like these.


Solution

  • The g? command (type :help g? for brief documentation) implements the rot13 algorithm, which rotates each letter 13 places forward or backward in the alphabet.

    I'm not sure how commonly it's used today, but on Usenet it used to be a common way to encode spoilers. For example, if I'm writing a post that gives away the ending of something that not everyone has seen, I might use rot13 to weakly encrypt part of the article. It's enough to make it impossible to read accidentally (unless you've had a lot of practice), but easy to read if you're using a newsreader that has a built-in rot13 function -- as most of them do.

    For example:

    Pretend this is a spoiler. Filter with rot13 to read it.

    would become

    Cergraq guvf vf n fcbvyre. Svygre jvgu ebg13 gb ernq vg.

    If I don't want to read the spoiler, I can ignore it. If I do want to read it, I can decrypt it easily enough.