On Mon, Nov 13, 2006 at 01:05:00PM -0600, Ben K. wrote:
> 
> Vimmers,
> 
> I have a long source code consisting of multiple modules wrapped in {}.
> Sometimes I use "*" to find the next match. But I'd like to search only 
> within the same module or class that I started from. (which is wrapped
> inside sub ... {})
> 
> In the following example, I'd like * or "n" to at least let me know that I
> crossed the module boundary for instance 3. Or not match it at all.
> If there's a way to highlight between the matching brackets
> (open/close),
> it would also be helpful, even if it doesn't allow highlighting of the
> searched pattern.
> 
> 
> sub aaa {
> ...
> instance 1    # Begin by "*"
> ...
> instance 2    # This is OK.
> ...
> }
> sub bbb {
> ...
> instance 3    # This is not what I want
> ...
> }
> 
> Is there a simple way to do it?

     If you are using vim 7.0, then you can take advantage of the
optional stopline argument in the search() function:

:let pat = '\<' . expand('<cword>') . '\>'
:let stopline = searchpair('{', '', '}', 'n')
:call search(pat, '', stopline)

Of course, that does not count as "simple," but you can wrap those three
lines in a function and map * to call it:

:nmap * :call MySearch()<CR>
fun! MySearch()
  let pat = '\<' . expand('<cword>') . '\>'
  let stopline = searchpair('{', '', '}', 'n')
  call search(pat, '', stopline)
endfun

Or you could choose another key, and of course there are various ways t
make it all more flexible.

     I am not sure exactly what sort of highlighting you want.

HTH                                     --Benji Fisher

Reply via email to