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

How do I force a case-sensitive search in Vim even when ignorecase is enabled?

Answer

/pattern\C

Explanation

Appending \C anywhere in a search pattern forces the entire search to be case-sensitive, regardless of whether ignorecase or smartcase is set. This is useful when you have case-insensitive searching enabled globally but need an exact, case-sensitive match for a specific search without temporarily changing your settings.

How it works

  • /pattern\C — the \C atom overrides ignorecase and forces case-sensitive matching for the whole pattern
  • The \C can appear anywhere in the pattern (beginning, middle, or end)
  • The complementary atom \c forces case-insensitive matching, even if noignorecase is set
  • Both atoms affect the entire pattern, not just the characters after them

Example

Suppose you have :set ignorecase active. Searching for /Error would match error, ERROR, and Error. To match only the exact capitalization:

/Error\C

This finds only Error, skipping error and ERROR.

Tips

  • Use \c in the pattern to force case-insensitive search even when noignorecase is set — useful for one-off case-insensitive matches in a case-sensitive setup
  • These atoms work in :substitute patterns too: :%s/Error\C/Warning/g replaces only exactly-cased Error
  • Combine with \C for precise replacements when your vimrc has ignorecase and smartcase set

Next

How do I accept a flagged word as correct for the current session without permanently adding it to my spellfile?