Saturday, November 12, 2011

N shaal ivz srngher: ebg13

I know the title is weird. Or is it really? Caesar wanted to send messages to his friends and girlfriends, but didn't want his enemies and Cleopatra to be able to read these messages in case they intercepted them. He came up with a wonderful cipher algorithm, nowadays called rot13.
In this note I just want to briefly talk about an amazing and ever so useful vim feature: yes, vim can encode and decode rot13! Just it can, out of the box! I know you can't believe it, so let me just show you how: The command is (in normal mode) g? followed by a movement. This will encode (or decode) the portion between the cursor and the endpoint defined by the movement.
For example, I have this stupid message to decode:
N shaal ivz srngher: ebg13

and I really want to know what it means. It's probably very important. So I just copy it on a line in vim and then (in normal mode) type g?ip (you know the movement ip, right? if not, try :h v_ip) and I obtain the decoded message!!! It's amazing, and it was really important, indeed!

Purref!

3 comments:

  1. Amazing! Thanks so much for this tip!

    ReplyDelete
  2. g?? would be quicker (it's what I did before reading the article: "+Pg??)

    ReplyDelete
    Replies
    1. Thanks for your comment. You're right it's quicker. I just wanted to mention the lesser known motion `i` something (inner).

      Delete