Reputation: 565
How can we search for a something in Vim, excluding some of the possibilities which the search would cover?
For example: Search for How\s[a-z]
but the result should not include How a
and should include How b
, How c
, ..., How z
.
UPDATE
One possible solution to the above illustrative example is How\s[b-z]
as pointed out by @Jonathon K, which is correct. But what I am looking for is a generic solution in which I can exclude one of the many possible solutions in a Vim search (Example 2: Exclude ERROR
when I search for er*
. Ad-hoc solutions could be there for this case as well :) ).
Upvotes: 1
Views: 1244
Reputation: 7669
Example 2: Exclude ERROR when I search for
er*
. Ad-hoc solutions could be there for this case as well.
Just FYI, er*
will not match ERROR
. It will match any of these:
e
er
errrrr
errrrrrrrrrrrrrrrrr
You're probably thinking of ER.*
Moving on from that...
You're basically looking for the \@!
quantifier. It asserts that the previous atom does not match at the current position. It's also zero-width. If you wanted to search for ER.*
but not match ERROR
, you could do this:
ER\(ROR\)\@!.*
Or as I prefer with "magic" on (\v
):
\vER(ROR)@!.*
Or with your first example:
\vHow\sa@![a-z]
Even though I would recommend using [b-z]
like Jonathon pointed out :)
Upvotes: 2