Thursday, October 3, 2024

Re: Finding all words

Very good idea. Thanks again.

Salman

On Thu, Oct 3, 2024, 12:09 Tim Chase <vim@tim.thechases.com> wrote:
On 2024-10-03 11:58, Salman Halim wrote:
> >     /.\{-}quick\&.\{-}brown\&.\{-}lazy\&.\{-}jumps/

> something that does the combination thing I was suggesting and time the two
> approaches, but with more than just two words: /quick.*brown\|brown.*quick/
> vs. /.\{-}quick\&.\{-}brown}/

At the cost of some redundancy, you might be able to speed it up a
little bit by requiring that it start with at least one of the words
like

  /\%(\<\%(quick\|brown\|lazy\|jumps\)\>\)\@=\%(.\{-}quick\&.\{-}brown\&.\{-}lazy\&.\{-}jumps\)/

so it won't start looking for the other terms until it's found at
least one of them, cutting out a lot of non-starter cases.

-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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/Zv7Bt-O8KlBggCtX%40thechases.com.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEeptRdJnWHNSPa2Kprm1By3VBf-_U2g5v%2BCq%2BK-g3Rr1A%40mail.gmail.com.

Re: Finding all words

On 2024-10-03 11:58, Salman Halim wrote:
> > /.\{-}quick\&.\{-}brown\&.\{-}lazy\&.\{-}jumps/

> something that does the combination thing I was suggesting and time the two
> approaches, but with more than just two words: /quick.*brown\|brown.*quick/
> vs. /.\{-}quick\&.\{-}brown}/

At the cost of some redundancy, you might be able to speed it up a
little bit by requiring that it start with at least one of the words
like

/\%(\<\%(quick\|brown\|lazy\|jumps\)\>\)\@=\%(.\{-}quick\&.\{-}brown\&.\{-}lazy\&.\{-}jumps\)/

so it won't start looking for the other terms until it's found at
least one of them, cutting out a lot of non-starter cases.

-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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/Zv7Bt-O8KlBggCtX%40thechases.com.

Re: Finding all words



On Thu, Oct 3, 2024 at 10:18 AM Tim Chase <vim@tim.thechases.com> wrote:
On 2024-10-03 15:09, Mikhail Velikikh wrote:
> > Is there a way to compose a regular expression in Vim that will find all
> > the words I want, irrespective of the order in which they occur?
>
> I would use something like this:
> \v<(quick|brown|lazy|jumps)>

That finds *any* of the words, not *all* of the words as the OP requested.

While the implementation can often end up slow if you have a large
text or lots of find-them-all terms, you (OP) can use

   :help /\&

to join the conditions like

    /.\{-}quick\&.\{-}brown\&.\{-}lazy\&.\{-}jumps/

-tim

Thank you; that's exactly what I was looking for. It does slow down, though, as you said it might, once I add more words to it. I might write something that does the combination thing I was suggesting and time the two approaches, but with more than just two words: /quick.*brown\|brown.*quick/ vs. /.\{-}quick\&.\{-}brown}/ 

Best regards,

Salman

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEcXmK25RhOrXZ9eA0PnogP76DKMr9gsBuD4sgm%2Bw6q_5Q%40mail.gmail.com.

Re: Finding all words

On 2024-10-03 15:09, Mikhail Velikikh wrote:
> > Is there a way to compose a regular expression in Vim that will find all
> > the words I want, irrespective of the order in which they occur?
>
> I would use something like this:
> \v<(quick|brown|lazy|jumps)>

That finds *any* of the words, not *all* of the words as the OP requested.

While the implementation can often end up slow if you have a large
text or lots of find-them-all terms, you (OP) can use

:help /\&

to join the conditions like

/.\{-}quick\&.\{-}brown\&.\{-}lazy\&.\{-}jumps/

-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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/Zv6nnfKqWolaBkMm%40thechases.com.

Re: Finding all words

Hi,

I would use something like this:
\v<(quick|brown|lazy|jumps)>

\v - very magic
< - the beginning of a word
> - the end of a word
(quick|brown|lazy|jumps) - the words to find

Thanks,
Mikhail Velikikh



On Thu, 3 Oct 2024 at 14:51, Salman Halim <salmanhalim@gmail.com> wrote:
Hello,

Is there a way to compose a regular expression in Vim that will find all the words I want, irrespective of the order in which they occur? For example:

Some text...
The quick red fox jumps over the lazy brown dogs.
Some other text...

I want to find 'quick', 'brown', 'lazy' and 'jumps'. I don't know the order in which they occur, so something like 'quick.*brown.*lazy.*jumps' won't work. I'm trying to avoid a complicated/ugly expression that includes all possible orderings like '\%(brown.*lazy\)\|\%(lazy.*brown\)'.

I'm hoping there is a more graceful way to do this already. I'm happy to write a function to convert a sequence of words to an expression, even if it's the 'all combinations' one.

Thank you,

--
 
Salman

I, too, shall something make and glory in the making.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEcUM43Z%3DOVF0cPXRGq_12NckWMHZBtdH0S_DpKOFJZUOg%40mail.gmail.com.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CALe4HpnpJwixWbdeS72jh-oWERq3_pjURDRgGpLsU8FCP6UyZg%40mail.gmail.com.

Finding all words

Hello,

Is there a way to compose a regular expression in Vim that will find all the words I want, irrespective of the order in which they occur? For example:

Some text...
The quick red fox jumps over the lazy brown dogs.
Some other text...

I want to find 'quick', 'brown', 'lazy' and 'jumps'. I don't know the order in which they occur, so something like 'quick.*brown.*lazy.*jumps' won't work. I'm trying to avoid a complicated/ugly expression that includes all possible orderings like '\%(brown.*lazy\)\|\%(lazy.*brown\)'.

I'm hoping there is a more graceful way to do this already. I'm happy to write a function to convert a sequence of words to an expression, even if it's the 'all combinations' one.

Thank you,

--
 
Salman

I, too, shall something make and glory in the making.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEcUM43Z%3DOVF0cPXRGq_12NckWMHZBtdH0S_DpKOFJZUOg%40mail.gmail.com.