Monday, November 8, 2010

Case insensitive vim searching

I don't know how I didn't learn this trick years ago. It's dead simple, but something that comes up fairly often: case insensitive searching.

It's fairly well known that in vim '/' is case sensitive search. That's almost always what I want, but very occasionally I want a case insensitive search. Search can be set to ignore case for the life of the vim session by using :set ignorecase (:set ic) and likewise :set noignorecase turns off the feature. That's really obnoxious if you only want one insensitive search. Luckily there's a better solution! Putting \c at the end of your search query makes only that search case insensitive.

2 comments:

  1. Try using "set ignorecase" AND "set smartcase" in your .vimrc. Now if you search for all-lowercase strings, it will be case-insensitive; if your query has one or more uppercase letters then it will be case-sensitive.

    If you still need to do a case-sensitive search for a lowercase string, you can do it using \C instead of \c.

    ReplyDelete
  2. Oh, thanks for the hint! That's in my vimrc now.

    I ran across http://www.linuxjournal.com/article/3805?page=0,0 looking up what those commands do. It's got some other good tricks too.

    ReplyDelete