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

How do I invert the case of an entire paragraph with one operator command?

Answer

g~ap

Explanation

g~ap is a fast way to invert letter case across a full paragraph without entering Visual mode. For experienced users, this shines when normalizing pasted content, fixing accidental caps, or preparing text for case-sensitive diffs. Because it is operator + text-object based, it stays composable and predictable.

How it works

  • g~ is Vim's case-toggle operator
  • ap targets a paragraph (including surrounding blank-line boundary semantics)
  • Combined as g~ap, Vim applies toggle-case to that full text object in one shot
  • It works like other operators (d, c, y) so your motion habits transfer directly

Example

Starting text with the cursor anywhere in the first paragraph:

Alpha beta
Gamma DELTA

unchanged line

Run:

g~ap

Result:

aLPHA BETA
gAMMA delta

unchanged line

Tips

  • Use g~ip for the inner paragraph variant if you do not want boundary whitespace included
  • Prefer guap or gUap when you want deterministic lower/upper casing instead of toggling
  • Repeat with . when applying the same transformation across nearby paragraphs

Next

How do I save only real file buffers when running bufdo across many open buffers?