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

How do I toggle the case of all characters in a visual selection?

Answer

~ (in visual mode)

Explanation

In visual mode, pressing ~ toggles the case of every character in the selection. Lowercase becomes uppercase and vice versa.

How it works

  • Select text with any visual mode
  • Press ~ to toggle case
  • Each character flips individually

Example

Hello World

Select with V, press ~:

hELLO wORLD

Tips

  • U converts selection to uppercase
  • u converts selection to lowercase
  • ~ toggles each character individually
  • g~{motion} toggles without visual mode
  • Works with all visual mode types including block

Next

How do you yank a single word into a named register?