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

How do I make the tilde key work as a case-toggle operator so I can use motions like ~w or ~ip?

Answer

:set tildeop

Explanation

By default, ~ toggles the case of a single character and advances the cursor. With set tildeop, ~ becomes a full operator — you can combine it with any motion or text object to toggle case across a range, just like d, y, or c.

How it works

Once tildeop is enabled:

  • ~w — toggle case of the current word
  • ~ip — toggle case of the inner paragraph
  • ~$ — toggle case from cursor to end of line
  • ~G — toggle case from here to end of file
  • 5~~ — toggle case of 5 lines (using ~~ as the line-wise form)

This mirrors how g~{motion} works, but lets you use the shorter ~ key as the operator.

Example

With cursor at the start of:

hELLO wORLD

Press ~$ to toggle case to end of line:

Hello World

Tips

  • g~{motion} always works as a case-toggle operator, even without tildeop — useful as a fallback when sharing configs
  • gU{motion} uppercases, gu{motion} lowercases — use these when you need a specific case rather than a toggle
  • Without tildeop, ~ still works character-by-character when used without a motion
  • Add set tildeop to your vimrc to make it permanent

Next

What built-in LSP keymaps does Neovim 0.10+ provide automatically when a language server is attached?