views:

198

answers:

1

Is something wrong in ":g-2-g/3/" or is the recursion in the global just missing? I can not understand a reason for the error:

E147: Cannot do :global recursive

How can I get a recursive global search in VIM?

[Neil's initial Suggestion with the operator \| ]

g/1.*2\|2.*1/

A disadvantage is that the combinations expand with n numbers. For three numbers, the number of combinations is 3! (=6) that is

g/1.*2.*3\|2.*1.*3\|3.*1.*2\|1.*3.*2\|2.*3.*1\|3.*2.*1/

For n numbers, the number of combinations is n!.

[Solution with the operator \&]

Brian Carper and Neil Butterworth figured out the solution. Great thanks for them!

g/.*1\&.*2\&.*3/

It is for the whole line:

g/.*1\&.*2\&.*3\&.*/
+1  A: 

New info: This does what you want - the "\&" sequence is the "and" operator:

g/.*1\&.*2\&.*3/

Brian Carper's (see comments, and thanks again) explanation:

/1\&2/ wouldn't work because both branches need to match "at the same position". /.*1\&.*2/ let the match anchor itself at the front of the line and then expand however much it needs to to find the numbers

anon
How would you do it with 3 numbers? g/1.*2.*3\|2.*1.*3\|3.*1.*2\|1.*3.*2\|2.*3.*1\|3.*2.*1/ Can you see that the number of combinations is n! for n number? The recursive global search would have only n number of combinations for n number. For n, it is just :g-1-g/2/g@[email protected]$n$. It would be cool!
Masi
Brian Carper
Ah - I understand! Thanks!
anon