How can I search and replace array[j] by array in the whole script?

I tried :%s/array[j]/array/ but that does not work.



You need to escape the brackets, as they are special characters used to indicate a list in a substitution.

Your command should be :%s/array\[j\]/array/g

  • I still get a " pattern not found" error message. – ALBERTO EDGAR CHAVARRIA RODRIG Jan 12 '18 at 7:16
  • Do you actually mean to replace only the ones with j - array[j]? Maybe you can paste some parts of the script so we can try on our machines. – Neaţu Ovidiu Gabriel Jan 12 '18 at 8:33
  • @ALBERTOEDGARCHAVARRIARODRIG If you're getting that message, then the pattern is either not in the file, or you are not escaping it properly. As Neatu suggests, you should post part of the file where you're trying to do the substitution. – Herb Wolfe Jan 12 '18 at 17:13
  • Here is a screenshot of my script dropbox.com/s/5w41dv1bg2x4mpo/search.png?dl=0. Please have a look. – ALBERTO EDGAR CHAVARRIA RODRIG Jan 12 '18 at 19:10
  • @ALBERTOEDGARCHAVARRIARODRIG Please edit your question to include a sample of the text from your file. – Herb Wolfe Jan 12 '18 at 21:40

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.