Case Changing

~ flips one character. gU/gu/g~ are operators.

Keys: ~, gU, gu, g~

~ toggles the case of the character under the cursor. gU is an uppercase operator; gu is lowercase; g~ toggles. Each takes a motion: gUiw uppercases the inner word.

Three operators for case: gU uppercases, gu lowercases, g~ toggles. Each takes a motion, just like d and y. ~ alone is a one-shot toggle of the character under the cursor.

Toggle case of cursor character
KeyNote
~
Uppercase inner word
KeyNote
g
U
i
w
Lowercase inner word
KeyNote
g
u
i
w
Toggle inner word
KeyNote
g
~
i
w
Uppercase whole line
KeyNote
g
U
U
~ โ€” toggle case
gU โ€” uppercase operator
gu โ€” lowercase operator
g~ โ€” toggle case operator
Doubled forms (gUU, guu, g~~)

Worked example โ€” gUw and ~

Change case without retyping.

Step 1 ยท
transform.case
Step 2 ยท gUw ยท gUw โ€” uppercase one word.
gUw โ€” uppercase one word.
Step 3 ยท 0~ ยท ~ โ€” toggle one char's case.
~ โ€” toggle one char's case.

gu/gU/g~ are operators; ~ is a one-shot toggle. With visual mode you can transform any selection.

โ–ถ Try this in the simulator

See also: The Universal Grammar, The Vim Grammar