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.


1 Answer 1


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. Jan 12, 2018 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. Jan 12, 2018 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
    Jan 12, 2018 at 17:13
  • Here is a screenshot of my script dropbox.com/s/5w41dv1bg2x4mpo/search.png?dl=0. Please have a look. Jan 12, 2018 at 19:10
  • 1
    @ALBERTOEDGARCHAVARRIARODRIG Please edit your question to include a sample of the text from your file.
    – Herb
    Jan 12, 2018 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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