4

Is there script or function for vim to do search of words that is not in proper location (sorry, i don't know how to put it in question) ?

Example: This is a vim user who like the functionality which is pure manual power.

Question: I want to search a sentence which contains words "power, vim , functionality".

I have to remember the order of the keywords to do search:

/vim.*functionality.*power

Only in this way, the result will be yielded. Which is not useful.

But if i don't remember the arrangement of those keywords.. Hence when i do a search :

/power.*vim.*functionality 

It will not give me the result i wanted.

What is the solution ?

Thank You in advance.

0

3 Answers 3

5

You can use a branch syntax \&,

/.*power\&.*vim\&.*functionality 

would find all lines containing all of these three words

Note that the .* are necessary as branch attempts to match all parts at the same location.

3
  • I just want to know for the sake of more diversity, otherwise i can use :LogiPat to do the search .
    – andrew_ysk
    Commented Sep 24, 2022 at 10:39
  • edited to clarify this is a search pattern
    – Mass
    Commented Sep 26, 2022 at 4:13
  • Somehow i manage to follow your syntax and get it. Thx
    – andrew_ysk
    Commented Apr 8, 2023 at 0:00
2

This is an excellent use case for the LogiPat built-in plugin. LogiPat builds regular expressions using boolean logic.

In your particular example, run:

:LogiPat "power"&"vim"&"functionality"

This uses search() internally. If you want to highlight your matches, type // as usual.

-2

I think this is the only solution, i tried and it works too:

/word3\|word1\|word2  

  

It will highlight the line with the words even when in random order.

1
  • 2
    this is any of not all of
    – Mass
    Commented May 14, 2022 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.