m (The power of "\ " in reg-ex moved to Search across multiple lines: Page moved by JohnBot to improve title) |
(Change to TipImported template + severe manual clean) |
||
Line 1: | Line 1: | ||
{{review}} |
{{review}} |
||
+ | {{TipImported |
||
− | {{Tip |
||
|id=242 |
|id=242 |
||
+ | |previous=241 |
||
− | |title=The power of "\_" in reg-ex |
||
+ | |next=243 |
||
− | |created=May 6, 2002 |
+ | |created=May 6, 2002 |
|complexity=intermediate |
|complexity=intermediate |
||
|author=vim_power |
|author=vim_power |
||
|version=6.0 |
|version=6.0 |
||
|rating=31/16 |
|rating=31/16 |
||
⚫ | |||
− | |text= |
||
− | One of the most uncelebrated |
+ | One of the most uncelebrated features of Vim is the ability to span a search across multiple lines. |
+ | <pre> |
||
⚫ | |||
+ | \_$ matches end-of-line anywhere in search pattern |
||
+ | \_s matches a space anywhere in search pattern |
||
+ | </pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | ==References== |
||
− | \_$ ---"----- end ----------------------"-------------------------. |
||
+ | *{{help|pattern}} |
||
⚫ | |||
− | \_s ---"------ space ------------"------------------------- . |
||
+ | To seek out HTML comments over ''multiple'' lines, for example: |
||
+ | <pre> |
||
⚫ | |||
⚫ | |||
+ | </pre> |
||
+ | Use the search: |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | However, 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. This is due to the default that improves highlighting performance. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | See [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:pattern}} :help pattern] for more details. |
||
− | |||
− | Njoy |
||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | This feature is absolutely great... |
||
− | |||
− | eg. to seek out HTML |
||
⚫ | |||
⚫ | |||
− | comments over MULTIPLE LINES |
||
− | |||
⚫ | |||
− | |||
− | does the trick. We used \{-} the "few as possible" operator |
||
⚫ | |||
− | such comments in the file. |
||
− | |||
⚫ | |||
− | 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?) |
||
− | |||
− | |||
− | |||
− | Hal Atherton |
||
− | , May 7, 2002 22:58 |
||
---- |
---- |
||
⚫ | |||
− | No this is not a bug, this is -- honest -- a feature! Specifically, this is a default that improves highlighting performance. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | For more info: |
||
− | |||
⚫ | |||
− | |||
− | jaldripublic at comcast dot vim |
||
− | , November 17, 2003 8:08 |
||
− | ---- |
||
− | To Hal Atherton, |
||
⚫ | |||
⚫ | |||
⚫ | |||
However, this one will spill over to the next comment if there's more than one so it's not too useful. |
However, this one will spill over to the next comment if there's more than one so it's not too useful. |
||
− | semovrs--AT--concord.edu |
||
− | , February 18, 2006 19:21 |
||
---- |
---- |
||
− | + | The TAB character is among the control chars, thus not matched with \p per default. |
|
− | '''Anonymous''' |
||
− | , February 22, 2006 3:56 |
||
---- |
---- |
||
− | <!-- parsed by vimtips.py in 0.569642 seconds--> |
Revision as of 01:39, 1 November 2007
created May 6, 2002 · complexity intermediate · author vim_power · version 6.0
One of the most uncelebrated features of Vim is the ability to span a search across multiple lines.
\_^ matches start-of-line anywhere in search pattern \_$ matches end-of-line anywhere in search pattern \_s matches a space anywhere in search pattern
e.g /{\_s will match 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).
References
Comments
To seek out HTML comments over multiple lines, for example:
<!-- foobar does not exist -->
Use the search:
/<!--\_p\{-}-->
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.
However, 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. This is due to the default that improves highlighting performance.
If you want to ensure the most accurate highlighting, try:
:syntax sync fromstart
This can slow things down on large files with complex highlighting :help :syn-sync
For some reason <!--\_p\{-}--> doesn't work if your comments are indented (with opening and closing comment tag indented).
Here's another way to highlight HTML comments using conventional regex:
/<\!--\(.\|\n\)*-->
However, this one will spill over to the next comment if there's more than one so it's not too useful.
The TAB character is among the control chars, thus not matched with \p per default.