In the following search in Vim I would like to ignore the case of the first letter:
/[tlcp]omo
I would like to know how the case can be ignored only on the first letter of the search pattern.
Vim has the following options to ignore case in the search pattern:
:set ignorecase
:set smartcase [ignora caso si no hay ninguna mayúscula en la búsqueda]
or use \c
at any position in the search pattern:
/hola\c => [encuentra hola y HOLA]
But all of these options ignore the case on the entire pattern, not a part of it.
One option to ignore the single-letter case of the search pattern is, using the []
regular expression collection, to specifically case each letter:
/[tTlLcCpP]omo
But is there a way to ignore case in a part of the search pattern without having to specify each and every uppercase and lowercase letter using regular expression?
Vim doesn't seem to allow it . Some languages (PHP or Go for example) allow in their regular expressions the flag
(?i)
that means to ignore the case from the point where it appears onwards, and also(?-i)
that it means not to be ignored. Using both you could assemble the expression:that as you can see in this demo works as you want.
On the other hand Vim, the closest thing it has, is the "magic character"
\c
to ignore the case or\C
not to ignore it. But they don't work from the point they appear onward, but no matter where they appear, they affect the entire regular expression. So this doesn't work:\c[tlcp]\Como
. They also don't restrict their effect to the capturing group they appear in but affect the entire regular expression, so this doesn't work either:\(\c[tlcp]\)\(\Como\)
.