search for one word and exclude another

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

search for one word and exclude another

Kamaraju S Kusumanchi
Hi
    I need to search for a word 'condition' (without quotes) and exclude
hits containing 'condition number'.

On a shell I can do

grep -sir condition *F90 | grep -v 'condition number'

How do I do it the vim way?

thanks
raju

--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/

Reply | Threaded
Open this post in threaded view
|

Re: search for one word and exclude another

Mika Fischer-4
* Kamaraju S Kusumanchi <[hidden email]> [2007-03-26 18:36]:
>     I need to search for a word 'condition' (without quotes) and exclude
> hits containing 'condition number'.
[...]
> How do I do it the vim way?

/condition\( number\)\@!

See also :help pattern-overview and :help /\@!

Regards,
 Mika
Reply | Threaded
Open this post in threaded view
|

Re: search for one word and exclude another

Charles E Campbell Jr
In reply to this post by Kamaraju S Kusumanchi
Kamaraju S Kusumanchi wrote:

>Hi
>    I need to search for a word 'condition' (without quotes) and exclude
>hits containing 'condition number'.
>
>On a shell I can do
>
>grep -sir condition *F90 | grep -v 'condition number'
>
>How do I do it the vim way?
>  
>
Sounds like a problem that LogiPat is designed to handle:

  :LP "condition" & !"condition number"

would do the trick.  If you want to see the pattern, you can use

  :echo LogiPat('"condition"&!"condition number"')

which shows

  \%(.*condition.*\&^\%(\%(condition number\)\@!.\)*$\)

You can get LogiPat from my website:

  http://mysite.verizon.net/astronaut/vim/index.html#LOGIPAT

or from

  http://vim.sourceforge.net/scripts/script.php?script_id=1290

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: search for one word and exclude another

Kamaraju S Kusumanchi
> You can get LogiPat from my website:
>
>   http://mysite.verizon.net/astronaut/vim/index.html#LOGIPAT
>
> or from
>
>   http://vim.sourceforge.net/scripts/script.php?script_id=1290

Wow! Super cool script. Just what I need. It solved my problem.

Thanks
raju

--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/

Reply | Threaded
Open this post in threaded view
|

Re: search for one word and exclude another

A.J.Mechelynck
In reply to this post by Kamaraju S Kusumanchi
Kamaraju S Kusumanchi wrote:

> Hi
>     I need to search for a word 'condition' (without quotes) and exclude
> hits containing 'condition number'.
>
> On a shell I can do
>
> grep -sir condition *F90 | grep -v 'condition number'
>
> How do I do it the vim way?
>
> thanks
> raju
>

Try

        :g/\<condition\>\%(\s\+number\>)\@!/p

Explanation of the pattern

        \<              begin of word (don't match "precondition")
        condition       matches itself
        \>              end of word (don't match "conditional")
         \%(             start subpattern
         \s\+            any number of whitespace (at least one)
        number          matches itself
        \>              end of word ("condition numbering" is different)
        \)              end subpattern
        \@!             subpattern must NOT match

For :g/pattern/p see ":help :g"


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
140. You'd rather catch a score on the web than watch the game as
      it is being played on tv.