0

I have the file with below content:

char  abc[35+1];
char  abc[35+1];
[123];
char a_wo_011[35+1];

I want to replace the [35+1] with say ABC But its not working. I am able to search the pattern with below command:

/[35+1\]

But if I try to replace it , it is not working:

:%s/[35+1\]/ABC/

I even tried tripple \\ from other post. Can you please advise what am I doing wrong and how to fix it? Thanks.

1 Answer 1

1

You need to escape [ instead of ] to indicate to Vim that you are not matching a collection of atoms but a litteral [

This should do the job:

%s/\[35+1]/ABC

See :h /collection

2
  • 1
    I tried everything but that. Thanks a lot for helping me. Will accept the answer after 5 minute limit. :) and thanks for explanation too Dec 4, 2018 at 16:32
  • @ForeverLearner you should read :h magic, this will make it easier to avoid explicitly escaping characters with special meaning. For example /\V[35+1]/ would work Dec 4, 2018 at 18:38

Your Answer

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

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