-2

I have a buffer that contains this sentence :

I go to a rendez-vous this evening.

and I have this function :

function MyFunction()
  let myList = ["rendez-vous"]
  let myFile = readfile(bufname(1))
  for elem in myList
      if match(myFile,elem)!=-1
              echo elem
          let elem2 = substitute(elem, '-', 'µ', 'gn')
          echo elem2
          exe '%s/'elem.'/'elem2    
      endif
  endfor
endfunction 

In my buffer, rendez-vous not become rendezµvous. Could you tell me why, please ?

2
  • 2
    that looks overly complicated and you haven't responded to my last comments, but my guess is your exe line does add whitespaces around the search pattern. But you did not really show a reproducible example, this is just a guess. BTW: what is the 'n' flag for in the substitute() call? – Christian Brabandt Mar 31 '20 at 14:44
  • Thank you. I have deleted the 'n' in the substitute and I have added '/gn' in the exe. It works now. – Arsene Asedrith Mar 31 '20 at 18:40
-1

This is the solution :

function MyFunction()
  let myList = ["rendez-vous"]
  let myFile = readfile(bufname(1))
  for elem in myList
      if match(myFile,elem)!=-1
              echo elem
          let elem2 = substitute(elem, '-', 'µ', 'g')
          echo elem2
          exe '%s/'.elem.'/'.elem2.'/gn'    
      endif
  endfor
endfunction 
2
  • Now you have the n flag in the :s command, so this won't replace anything. I don't understand what is wrong with :%s/-/µ/ge? – Christian Brabandt Apr 1 '20 at 5:56
  • That just scratches the surface as far as what is not understood about this person. They've asked 10 questions. 7 were answered. They've given 0 accepts or upvotes. For at least 3 of the answers they copied the key parts into their own answer, potentially siphoning off rep from the original answers. So far the 4 or 5 comments with advice/guidance and/or questions about their activity have been completely ignored. Which is what we all should start doing with any future questions from them. – B Layer Apr 1 '20 at 9:17

Your Answer

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

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