Re: Another search 'n' highlight question

2011-03-25 Thread Tim Chase

On 03/25/2011 09:37 PM, meino.cra...@gmx.de wrote:

possible to do two totally different searches in the function
and get highlighted the matches of *both* searches when the
function returns control to the user. Due to teh complexity of
the regular expressions of that matches it will be nearly
impossible to combine both searches into one.


Well, the general method would be something like

  let @/='\%('.pattern1.'\)\|\%('.pattern2.'\)'

Without having the exact regexps, it's somewhat hard to tell if 
there are any hidden gotchas (things that come to mind would be 
capture-groups and back-references in both patterns; SOL/EOL 
anchors in both patterns; modality-altering flags like \c or 
\V that would alter both pieces; etc).  You might even be able 
to do something like


 function! Foo()
  /complex_pattern1/
  let pattern1=@/
  /complex_pattern2/
  let pattern2=@/
  let @/='\%('.pattern1.'\)\|\%('.pattern2.'\)'
 endfunction

Alternatively, you can use matches for the highlighting instead 
of searches/search-highlighting if you don't need to use n/N to 
jump between hits.  Something like this (untested)


 function! Foo()
   call matchdelete(1)
   /complex_pattern1/
   call matchadd('Search', @/, 10, 1)
   /complex_pattern2/
   call matchadd('Search', @/, 10, 1)
 endfunction

might do the trick.  Finally, you might look at Dr. Chip's 
logipat.vim which simplifies some of the pattern-combining.


-tim




--
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Re: Another search 'n' highlight question

2011-03-25 Thread meino . cramer
Tim Chase v...@tim.thechases.com [11-03-26 04:04]:
 On 03/25/2011 09:37 PM, meino.cra...@gmx.de wrote:
 possible to do two totally different searches in the function
 and get highlighted the matches of *both* searches when the
 function returns control to the user. Due to teh complexity of
 the regular expressions of that matches it will be nearly
 impossible to combine both searches into one.
 
 Well, the general method would be something like
 
   let @/='\%('.pattern1.'\)\|\%('.pattern2.'\)'
 
 Without having the exact regexps, it's somewhat hard to tell if there 
 are any hidden gotchas (things that come to mind would be 
 capture-groups and back-references in both patterns; SOL/EOL anchors in 
 both patterns; modality-altering flags like \c or \V that would 
 alter both pieces; etc).  You might even be able to do something like
 
  function! Foo()
   /complex_pattern1/
   let pattern1=@/
   /complex_pattern2/
   let pattern2=@/
   let @/='\%('.pattern1.'\)\|\%('.pattern2.'\)'
  endfunction
 
 Alternatively, you can use matches for the highlighting instead of 
 searches/search-highlighting if you don't need to use n/N to jump 
 between hits.  Something like this (untested)
 
  function! Foo()
call matchdelete(1)
/complex_pattern1/
call matchadd('Search', @/, 10, 1)
/complex_pattern2/
call matchadd('Search', @/, 10, 1)
  endfunction
 
 might do the trick.  Finally, you might look at Dr. Chip's logipat.vim 
 which simplifies some of the pattern-combining.
 
 -tim
 
 
 
 
 -- 
 You received this message from the vim_use maillist.
 Do not top-post! Type your reply below the text you are replying to.
 For more information, visit http://www.vim.org/maillist.php
 

Hi Tim,

thanks a lot ! :)

Best regards
mcc

-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php