There are different approaches depending on the context.
: if any (in the current line do foo: endif
You can use search() according to @Kent's answer. It supports the {stopline} argument to avoid that it goes beyond the current line (which you can pass through line('.') ). But it only searches in one direction (forward or backward), so you will need to place the cursor.
So, it seems that if getline('.') =~ '(' Is the best test. It compares regular expressions of the current line with ( . Instead, you can use match() (look for any function via :help for full API documentation and BTW examples) or non-regexp stridx() (which can be faster, but also less readable).
: if / searchtarget succeeds, do bar: endif
Again, this sounds like a use for search() , which will move the cursor to a match, for example /search . But you can also use the latter (with :normal ) and check the transition by comparing the cursor positions (obtained with getpos('.') ) Before and after the command.
source share