I Have this function :

function! Test1()
     let myWord = "accroche-coeur"
     let cont1 = "-"
     if match(myWord,cont1)>=0  " if myWord contains cont1
         echo "Ok"
         echo "No"

I vould like make a function like that :

function! Test2()
   let cont1 = "irr"
   let myRep = "YesOrNo"
   silent! exe  '1,1 s/[A-Z-a-z-à-ù]*[A-Z-a-z-à-ù]/\=execute(if (search,cont1)>=0 then myRep="Yes" endif)'
   echo myRep

Could you tell me please what I have to insert between the parenthesis of execute( ... ) for that returns "Yes" if my text contains cont1.

For example, if I have this text :

Books are the mirror of the soul.

This function has to return "Yes"

  • 1
    Bienvenue à Vi and Vim! You might want to read :help expr; one if the constructs is a ternary conditional – D. Ben Knoble Feb 9 at 13:11
  • Are you searching for that text irr in line 1 of your buffer? That's what it looks like from the 1,1 before the s/.... Can you be more specific in describing where exactly you want to search for that term? – filbranden Feb 9 at 22:30
  • In the line 1, for each word, I would like to know if it contains irr – Arsene Asedrith Feb 10 at 2:14
  • Something like that : while search ("[A-Z-a-zà-ù]*[A-Z-a-zà-ù]", 'W') if search = "mirror" echo "search" endif endwhile – Arsene Asedrith Feb 16 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.