multiple search threads in vim?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

multiple search threads in vim?

Neil Zanella
Hello all,

It's been a while since I posted to the vim mailing list. I have an idea for vim
which I would like to share. Suppose an API has two functions named
lock(params) and unlock(params). The vim user knows that every
lock(params) must be followed by an unlock(params). The
parameters may differ.

So the vim user wants to search simultaneously the source file
in such a way that:

- when the user presses key "A" the next match for "lock()" is
  presented

- when the user pressed key "B" the next match for "unlock()" is
  presented

but alas, vim only offers one "*" or / or N n key for a single search
only, so the user cannot press A, B, A, B, etc... to check this
matching.

Suggestions welcome

Regards,

Neil
Reply | Threaded
Open this post in threaded view
|

RE: multiple search threads in vim?

Bloom, Greg
Maybe do:

:map A /lock()^V^[  (<--that's ctrl-V escape)
:map B /unlock()^V^[

Then the behavior is as you described: when you press A, you find the
next lock(), and when you press B you find the next unlock().



-----Original Message-----
From: Neil Zanella [mailto:[hidden email]]
Sent: Thursday, June 30, 2005 11:46 AM
To: [hidden email]
Subject: multiple search threads in vim?

Hello all,

It's been a while since I posted to the vim mailing list. I have an idea
for vim
which I would like to share. Suppose an API has two functions named
lock(params) and unlock(params). The vim user knows that every
lock(params) must be followed by an unlock(params). The
parameters may differ.

So the vim user wants to search simultaneously the source file
in such a way that:

- when the user presses key "A" the next match for "lock()" is
  presented

- when the user pressed key "B" the next match for "unlock()" is
  presented

but alas, vim only offers one "*" or / or N n key for a single search
only, so the user cannot press A, B, A, B, etc... to check this
matching.

Suggestions welcome

Regards,

Neil
Reply | Threaded
Open this post in threaded view
|

Re: multiple search threads in vim?

Tim Chase-2
In reply to this post by Neil Zanella
> but alas, vim only offers one "*" or / or N n key for a single search
> only, so the user cannot press A, B, A, B, etc... to check this
> matching.

Well, I suppose you could always do

/\(un\)\=lock()

which will search for the next of either...If they shouldn't be
nested, you might be able to do something like

:g/\<lock/let i=line(".")+1 | while getline(i)!~"unlock()" | if
getline(i)=~'\<lock' | echo i.": ".getline(i)| endif | let i=i+1
| endwhile

which could be wrapped in a function if you really wanted.  This
finds any instances of "lock()" that occur between an opening
"lock()" and closing "unlock()" pair.  It doesn't find any extra
unlockings...for that you might need something like

For that, you can use

/unlock()\(\_.\(\<lock()\)\@!\)*unlock()

which will find you the next "unlock()" that's followed by a
second "unlock()" statement that doesn't have a "lock()"
statement between them.

Hope this gives you some fodder for finding mismatched pairs,

-tim





Reply | Threaded
Open this post in threaded view
|

Re: multiple search threads in vim?

Hari Krishna Dara
In reply to this post by Neil Zanella

On Thu, 30 Jun 2005 at 6:45pm, Neil Zanella wrote:

> Hello all,
>
> It's been a while since I posted to the vim mailing list. I have an idea for
vim

> which I would like to share. Suppose an API has two functions named
> lock(params) and unlock(params). The vim user knows that every
> lock(params) must be followed by an unlock(params). The
> parameters may differ.
>
> So the vim user wants to search simultaneously the source file
> in such a way that:
>
> - when the user presses key "A" the next match for "lock()" is
>   presented
>
> - when the user pressed key "B" the next match for "unlock()" is
>   presented
>
> but alas, vim only offers one "*" or / or N n key for a single search
> only, so the user cannot press A, B, A, B, etc... to check this
> matching.
>
> Suggestions welcome
>
> Regards,
>
> Neil
>
>

You already couple of useful replies, but how about taking advantage of
the matchit plugin and use % to go from lock() to unlock() ? I think you
would do it something like this (untested):

let b:match_words = '\<lock\s*(:\<unlock\s*('

If you already have some match_words defined, you can consider appending
this:

let b:match_words = b:match_words.',\<lock\s*(:\<unlock\s*('

You can then search for "lock\s*(" and whether you land on lock( or
unlock(, you can find the matching call using "%".

--
HTH,
Hari


               
__________________________________
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html 

Reply | Threaded
Open this post in threaded view
|

Re: multiple search threads in vim?

Antony Scriven
In reply to this post by Bloom, Greg
On Jun 30, Bloom, Greg wrote:

 > Maybe do:
 >
 > :map A /lock()^V^[  (<--that's ctrl-V escape)
 > :map B /unlock()^V^[

I wonder how many people on this list are running in
vi-compatible mode. :-)

Antony