What would be the following vim regex to get the word term in:

hello my*term*here 

My thought was:


But it seems like there are some things I need to escape here that aren't working. The following works, but I really have no idea why -- why does the * not need to be escaped the first time but it does the second?


1 Answer 1


You do need to escape the * (with \*) since a * by itself means "zero or more repetitions of the preceding item."

When the * appears as the first character of the regular expression, that's an exception, since there's no preceding item, it will match a literal asterisk instead.

Note that inside a [...] character class, you typically don't need to escape characters with \, since metacharacters lose their special properties inside them.

The most correct (assuming the default setting for 'magic') would be:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.