How do I make a single search case-insensitive without changing my global ignorecase setting?
Answer
/pattern\c
Explanation
Vim's \c and \C atoms let you override the global ignorecase and smartcase settings on a per-search basis. Adding \c anywhere in a pattern forces case-insensitive matching for that search only, while \C forces case-sensitive matching.
How it works
\c— makes the entire pattern case-insensitive, regardless ofignorecase/smartcase\C— makes the entire pattern case-sensitive, regardless ofignorecase- Both atoms affect the whole pattern, no matter where they appear
Example
With set ignorecase smartcase active (case-sensitive when uppercase is present):
/Error ← case-sensitive (uppercase E triggers smartcase)
/Error\c ← case-insensitive: finds "error", "ERROR", "Error"
With set noignorecase:
/error ← case-sensitive by default
/error\c ← overrides: finds "error", "Error", "ERROR"
/Error\C ← forces case-sensitive even if ignorecase is on
You can place \c or \C at the start, end, or anywhere in the pattern — they always apply to the full search.
Tips
- Use
\cwhen you know you want a case-insensitive one-off search without reconfiguring settings - Use
\Cin patterns used in scripts or autocommands where you need guaranteed case-sensitive behavior regardless of user config - Works in substitutions too:
:%s/pattern\c/replacement/g