I have encountered some situations where I need to check if a value matches a regex in a list of regexes. For instance, say I have a list of regexes which match filetypes:
['gundo', 'nerdtree', 'git*']
I need to find out if the filetype of the current file matches any of these regexes. The way I would do it currently would look like this:
fun! IsIgnored()
for ignored_ft in ignored_filetypes
if &filetype =~ ignored_ft
return 1
endif
endfor
return 0
endfun
However, it would be nice if there was a shorter way of doing this. Does vim have a function to do this, or do I just have to stick with the for loop?
git*
matchesgi
,git
,gitt
, etc. This is easily fixed by usinggit.*
instead. Be careful not to use glob syntax, as is common when looking at file names and file types.