Ignore case when searching

3.7
(125)

Searching, or pattern matching, is a foundational Vim skill that everyone must master. A simple tap of / followed by a string to match or regular expression is all it takes. By default, these patterns are case sensitive. Searching for FooBar will not match references to foobar. There are two options to improve this behavior that I’d recommend to everyone:

  • set ignorecase – Makes pattern matching case-insensitive
  • set smartcase – Overrides ignorecase if your pattern contains mixed case

With this powerful combination of options, you get the best of both worlds: Using lowercase in your pattern will automatically match any case. But using one or more uppercase characters in your pattern will restrict matches to exact, case-sensitive matches.

Here’s a gif where I demonstrate these two options in practice. I first enable them from Vim command mode. (Consider add those to your .vimrc if you like them.) Then I search for colin in lower case. You can see it matches every reference, including the mixed-cased Colin. That is thanks to ignorecase. Next, I search for Colin. Because I’ve enabled smartcase, Vim knows I want a case-sensitive search and finds only the exact match. Try it out!

Also check out these two previous search-related posts:


Was this useful? Help us improve!

With your feedback, we can improve VimTricks. Click a link to vote:

How useful was this tip?

Average rating 3.7 / 5. Vote count: 125

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

81 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

Leave a reply

Your email address will not be published. Required fields are marked *