tags:

views:

1674

answers:

1

I notice the standard regex syntax for matching across multiple lines is to use /s, like so:

This is\nsome text
/This.*text/s

This works in Perl for instance but doesn't seem to be supported in Vim. Instead, I have to be much more specific:

/This[^\r\n]*[\r\n]*text/

I can't find any reason for why this should be, so I'm thinking I probably just missed the relevant bits in the vim help.

Can anyone confirm this behaviour one way or the other?

+20  A: 

Yes, Perl's //s modifier isn't available on Vim regexes. See :h perl-patterns for details and a list of other differences between Vim and Perl regexes.

Instead you can use \_., which means "match any single character including newline". It's a bit shorter than what you have. See :h /\_..

/This\_.*text/
Brian Carper
Very informative. Thank you Brian!
Daniel
http://blog.vinceliu.com/2007/12/regular-expression-matching-more-than.html
Quintin Par
Nice - my life just got a little easier. I'd been doing (.|\n)*
ojrac