Vim logo vim online Vim Book Ad

 Tip #242: The power of "\_" in reg-ex

 tip karma   Rating 19/13, Viewed by 1071 

created:   May 6, 2002 11:32      complexity:   intermediate
author:   vim_power      as of Vim:   6.0

One of the most uncelebrated feature of vim 6.0 is the ability to span a search across multiple lines.

\_^   maps a begining of line anywhere in search pattern.
\_$   ---"----- end           ----------------------"-------------------------.
\_s  ---"------ space                   ------------"------------------------- .

e.g  /{\_s will map all white spaces and new-line chars after a "{"

The \_ can be appended to other objects as well. such as \_U,  \_L,  \_. (this one's risky) .

See :help pattern for more details.
Njoy

 rate this tip  Life Changing Helpful Unfulfilling 

<<"Hide" Folding Markers | Develop vim modules on Win >>

Additional Notes

Hal Atherton, May 7, 2002 22:58
This feature is absolutely great...

eg. to seek out HTML
<!-- foobar does
      not exit -->
comments over MULTIPLE LINES

/<!--\_p\{-}-->

does the trick.   We used \{-} the "few as possible" operator
rather than * which is too greedy when there are many
such comments in the file.

The key is of course \_p which is printable characters including EOL
end-of-lines.

VIM BUG:
the highlighting is very erratic when the span over number of lines
exceeds, say, 30.    And highlighting is rather spotty when there are
shifts in screen views.   In other words:  HIGHLIGHTING UNRELIABLE.

FIX?
(some simple option we can reset?)

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo