I want to run a function with a condition that checks for ANSI color escape codes when I open files but I don't know how to write the condition.

I expect it to look something like this:

if ? '^[[0;32m'
    " stuff to do...

(^[[0;32m contains a control character instead a literal '^[')

How do I write this?


1 Answer 1


You can use the search() function. Something like this should work:

if search('\e\[\d\+;\d\+m', 'nW')>0

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