Multi-line regex support in Vim


Regex Problem Overview

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

This is\nsome text

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


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?

Regex Solutions

Solution 1 - Regex

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 /\_..



All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDanielView Question on Stackoverflow
Solution 1 - RegexBrian CarperView Answer on Stackoverflow