Step 7 of 7

8. Searching

Intelligently setting case sensitivity

Vim has a really nice option for setting case sensitivity intelligently. It’s called smartcase, and it makes your search case sensitive if your search pattern uses uppercase characters.

You can enable it with :set ignorecase followed by :set smartcase and disable it with :set nosmartcase.

Work through the checklist below. With smartcase on, a search for needle still matches every case variant — but a search for Needle, with its capital letter, only matches the capitalized ones. Watch the highlights change between the two searches.

  1. Turn on ignorecase Case insensitive search is the base that smartcase builds on — type :set ignorecase and hit Enter.
  2. Turn on smartcase Now capital letters in a pattern will switch case sensitivity back on — type :set smartcase and hit Enter.
  3. Search in all lowercase Every needle and Needle matches, regardless of case — type /needle and hit Enter.
  4. Jump down to the list of needles The bottom of the demo has a little list of needles — keep pressing n until you land on the first needle in that list.
  5. Search with a capital letter This time only the capitalized Needle lines match — type /Needle and hit Enter to land on the first one below you.
Turn on ignorecase Case insensitive search is the base that smartcase builds on — type :set ignorecase and hit Enter.

Next: Turn on smartcase

Loading editor…