Vimscript: Regex equal operator

=~ matches strings with regular expressions.

You use single quotes so you don't need to double escape escape sequences like \s etc.

function Hi()
  if "hello" =~ 'hel.o'
    echo "you said hello"
  else
    echo "you didn't say hello"
  endif
endfunction

:call Hi() will print you said hello.

vimscript

Edit on github
comments powered by Disqus
Click me