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.

andrew_ysk
  • 389
  • 2
  • 12

3 Answers3

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.

Mass
  • 14,080
  • 1
  • 22
  • 47
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.

r_31415
  • 576
  • 4
  • 13
-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.

andrew_ysk
  • 389
  • 2
  • 12