How do I ROT13-encode text using a built-in Vim operator?
Answer
g?{motion}
Explanation
Vim has a built-in ROT13 encoding operator: g?. Like d, c, and y, it takes a motion and operates on the text covered by that motion — but instead of deleting or yanking, it applies ROT13 rotation (shifting each letter by 13 positions in the alphabet). It is a fun oddity with some practical uses.
How it works
g?{motion}— ROT13-encode the text covered by the motiong??org?g?— ROT13-encode the current lineg?iw— ROT13-encode the word under the cursorg?ip— ROT13-encode the entire paragraph- In Visual mode: select text, then
g?
Example
Original: Hello World
After g?iw on Hello: Uryyb World
After g?$: Uryyb Jbeyq
Applying g? twice returns to the original text (ROT13 is its own inverse).
Practical uses
- Hide spoilers in plain text: ROT13-encode a movie spoiler so readers must actively decode it
- Simple obfuscation for puzzle answers, Easter eggs, or trivia in text files
- Testing — quick reversible transformation to verify operator-motion combinations work correctly
- Fun — it is a classic Unix tradition dating back to Usenet
Tips
- ROT13 only affects ASCII letters (a-z, A-Z); numbers, punctuation, and Unicode are unchanged
g?is a full operator — it works with any motion or text object, supports counts, and is dot-repeatable- There is no built-in ROT47 or Caesar cipher with custom shift —
g?is hardcoded to 13 - The tr command can also do this:
:%!tr 'A-Za-z' 'N-ZA-Mn-za-m'