vimtricks.wiki Concise Vim tricks, one at a time.

How do I ROT13 encode text using visual mode in Vim?

Answer

g?

Explanation

Vim has a built-in ROT13 encoding operator accessible via g?. When used in visual mode, it encodes the selected text by shifting each letter 13 positions in the alphabet. Applying it twice restores the original text, making it a simple toggle.

How it works

  • g? — the ROT13 operator
  • In visual mode, g? encodes the entire selection
  • In normal mode, use g?{motion} to encode a text range
  • Only affects ASCII letters (a-z, A-Z) — numbers and symbols are unchanged

Example

Before: Hello World
After g?: Uryyb Jbeyq
After g? again: Hello World (back to original)

Tips

  • Use g?g? or g?? to ROT13 the current line in normal mode
  • g?iw encodes a single word
  • ROT13 is commonly used to hide spoilers in plain text
  • This is a real operator — it works with any motion: g?ap for a paragraph, g?i{ for a block

Next

How do I return to normal mode from absolutely any mode in Vim?