3 Ways of Making Case Insensitive Search in Vim/Vi

By default, Vim/Vi’s search is case sensitive. However, if I want to search case insensitively, is there any method? For example, I search for dog, instead of matching dog only case sensitively, I also want to find out phases containing Dog, DOg, etc.

There are several methods:

1. Setting the search to be case insensitive in Vim

Set vim to ignorecase:

:set ignorecase

dog will match Dog, dog, or DOg.

To unset it:

:set noignorecase

You can also put it to your .vimrc if you want the behavior to be the default one.

2. Using \\c or \\C in search pattern

You can also force a pattern to be case insensitive or sensitive by adding \c or \C regardless the setting of the settings of ignorecase.

For example, the search with /dog\c is always case insensitive. And /dog\C is always case sensitive.

3. Use smartcase

The smartcase can only be used when the search pattern is typed and ignorecase option is on.

To enable it:

:set ignorecase
:set smartcase

If your search pattern is purely lowercase, it will search case insensitively.

If your search pattern contains uppercase characters, it will search case sensitively.

Similar Posts

  • How to set the number of mappers and reducers of Hadoop in command line?

    How to set the number of mappers and reducers of Hadoop in command line? Number of mappers and reducers can be set like (5 mappers, 2 reducers): -D mapred.map.tasks=5 -D mapred.reduce.tasks=2 in the command line. In the code, one can configure JobConf variables. job.setNumMapTasks(5); // 5 mappers job.setNumReduceTasks(2); // 2 reducers Note that on Hadoop…

  • MFC程序使用系统风格界面

    VC6默认编译出来的程序在XP下Luma风格下运行也是Windows的经典界面, 有损界面的美观与统一. VC2008默认设置下如果不是使用的unicode也是如此. 本文给出使VC6和VC2008可以编译出使用系统界面风格的解决方案. 1. 使VC6编译出使用系统风格的程序 步骤如下: 1) 创建一个.manifest文件的资源. 在res/文件夹下创建一个跟以程序名加.manifest的文件, 如果程序为test.exe, 则创建test.exe.manifest 文件可由此下载: https://www.systutorials.com/t/g/programming/resultcollector.manifest/ 注意要使用utf-8编码保存。 2) 将新定义的资源加入到.rc2文件中, 类型设为24. 打开res/文件夹下的.rc2文件, 在其中加入如下定义: 1 24 MOVEABLE PURE “res/test.exe.manifest” 其中的文件地址按1)步中修改的设置即可. 之后编译即可, 为了使程序界面可能充分利用系统的界面特性, 可以将界面字体设置为TrueType类型的, 利用Windows XP等系统的屏幕字体平滑特性. 2. 使VC2008编译出使用系统风格的程序 在VC2008下就比较简单了, 如果程序字符集使用unicode则默认就是使用系统界面风格的, 如果选择其它的类型, 则编辑下stdafx.h即可. 最后面部分找到这么一段: #ifdef _UNICODE #if defined _M_IX86 #pragma comment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′ processorArchitecture=’x86′ publicKeyToken=’6595b64144ccf1df’ language=’*'””) #elif defined _M_IA64 #pragma comment(linker,”/manifestdependency:”type=’win32’…

  • How to make Ubuntu Linux boot to text mode?

    My Ubuntu boots to GUI mode by default. How to make Ubuntu Linux boot to text mode? If you are using Ubuntu older than 16 such as Ubuntu 14.04: Edit /etc/default/grub Change GRUB_CMDLINE_LINUX=… to GRUB_CMDLINE_LINUX=”text”. Backup your old grub config`$ sudo cp -n /etc/default/grub /etc/default/grub.bak-date +%s ` Update grub$ sudo update-grub If you are using…

  • How to test whether a file exists and is a block special file in Python on Linux?

    Bash has a -b test to test whether a file exists and is a block special file. -b file True if file exists and is a block special file. How to do this in Python? Python’s stat module provides the similar functions for the C standard APIs and macros underlining such as stat() and S_ISBLK()….

  • |

    Statically Linking C and C++ Programs on Linux with gcc

    Before statically linking you C and C++ programs, you should be aware of the drawbacks of the static linking especially with glibc. There are some good discussions already: with glibc you’re linking static programs which are not really static and some others here and here. That said, you can choose to statically link C and…

6 Comments

  1. The second method above is incorrectly stated and should read (see vim ‘:help /\c’):
    2. You can also force a patten to be case insensitive or sensitive by \c or \C regardless the setting of ignorecase.

    For example, the search /dog\c is always case insensitive. And /dog\C is always case sensitive.

      1. Method 3 (smartcase). My experience is that if the search is just small letters, it only finds small letters. It is NOT case insensitive as you said. For example, /the will find “the” but not “The”.
        If it were case insensitive /the would find both “the” and “The”

        1. We added some screenshots in the post to illustrate the methods. From our tests, it works as expected after the smartcase is set. If it still does not work to you, you may check the vim version you are using and whether there are some special configurations.

        2. UPDATE
          I checked my _vimrc file and did not include ‘set ignorecase’. With ‘set ignorecase’ added, then ‘set smartcase’ works as described in the article (/The only finds The, but /the finds the and The).

          Help (options.txt) states ” Only used when the search pattern is typed and ‘ignorecase’ option is on.” = Has no effect unless ignorecase is on.

Leave a Reply

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