To perform a case-insensitive search in Vim, you can use the \c
or \C
modifier in your search pattern. Here's how you can do it with examples:
Using
\c
Modifier:When you add
\c
at the beginning of your search pattern, Vim will perform a case-insensitive search for that specific search. For example:vim
/searchword\c
This will search for "searchword" in a case-insensitive manner.
Example:
Let's say you have the following text in your Vim buffer:
vbnet
This is a Sample Text for Searching
sample Text is here
This is some more sample text
If you run the command:
vim
/sample\c
Vim will highlight the matches for "sample" regardless of case, and you can navigate through them using n
and N
:
vbnet
This is a Sample Text for Searching
sample Text is here
This is some more sample text
Using \C
Modifier:
On the other hand, if you add \C
at the beginning of your search pattern, Vim will perform a case-sensitive search, even if your Vim settings are set to be case-insensitive by default. For example:
vim
/searchword\C
This will search for "searchword" in a case-sensitive manner.
Example:
Let's use the same text as in the previous example:
vbnet
This is a Sample Text for Searching
sample Text is here
This is some more sample text
If you run the command:
vim
/Sample\C
Vim will highlight only the case-sensitive match for "Sample":
vbnet
This is a Sample Text for Searching sample Text is here This is some more sample text
Note that "sample" is not matched in this case because we used the
\C
modifier.
To summarize, you can use either \c
for case-insensitive searches or \C
for case-sensitive searches in Vim by adding them at the beginning of your search pattern. This allows you to control the case sensitivity of your searches as needed.
Comments
Post a Comment