No edit summary |
No edit summary |
||
Line 63: | Line 63: | ||
---- |
---- |
||
The script attached to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=256743 offers a convenient way to address this issue, you can type ":S foo bar" and it is translated to "/sfoo\_s\+bar" |
The script attached to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=256743 offers a convenient way to address this issue, you can type ":S foo bar" and it is translated to "/sfoo\_s\+bar" |
||
+ | |||
+ | The following works even better for me: |
||
+ | |||
+ | copy |
||
+ | |||
+ | :py <<EOF |
||
+ | import vim |
||
+ | def MySearch(*args): |
||
+ | s="\\_s\\+".join(args) |
||
+ | vim.command("/"+s) |
||
+ | EOF |
||
+ | command -nargs=* -complete=tag S :py MySearch(<f-args>) |
||
+ | |||
+ | into a file ~/.vim/project/blanksearch.vim |
||
+ | |||
+ | Note the tab (not spaces!!!) in the two indented lines. |
||
+ | |||
+ | The advantage of this version is that N and n work afterwards. |
Revision as of 00:40, 3 November 2008
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:
/
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 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.
The script attached to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=256743 offers a convenient way to address this issue, you can type ":S foo bar" and it is translated to "/sfoo\_s\+bar"
The following works even better for me:
copy
:py <<EOF import vim def MySearch(*args): s="\\_s\\+".join(args) vim.command("/"+s) EOF command -nargs=* -complete=tag S :py MySearch(<f-args>)
into a file ~/.vim/project/blanksearch.vim
Note the tab (not spaces!!!) in the two indented lines.
The advantage of this version is that N and n work afterwards.