How do I match any character including newlines in a Vim search?
Answer
/\_.pattern
Explanation
The \_. atom matches any single character including a newline. This extends the standard . which matches any character except newline.
How it works
.matches any character except newline\_.matches any character including newline\_.\{-}is the non-greedy version (matches as few as possible)
Example
Search for start followed by end with anything in between, even across lines:
/start\_.*end
This matches from start on any line to the next end, even if they are on different lines.
Tips
\_smatches whitespace including newline\_[]extends character classes to include newline\_^matches start of line (like^) in multi-line context- Multi-line searches can be slow — use with care on large files