I have to replace a lot of variables s1.size() with wa, and replace s2.size() with wb accordingly. I have made next substitution request:


But it wont work. Also, if I remove that w from replacement field,


it does almost what I want but of course it will replace just s1.size() with a and s2.size() with b without w.

How to put the vim script evaluation command \= and some text together in replacement field of substitute command?

I could not find help about \= with :help, if you know, please provide me a correct prompt to get vim help about \= command.

1 Answer 1


You can find help about the \= sub-replace-special command under :help :s\= (agreed, that's not very obvious.)

In any case, you can see that it says "When the {string} starts with \= it is evaluated as an expression", which indicates it can only be used at the beginning of a replacement and not in the middle.

In order to fix that for your issue, it seems the simplest is to simply include the "w" as part of the replacement in each value in your Dict:


Or another possibility, to avoid repetition (especially when instead of "w" you have a longer replacement) is to use the . operator to concatenate strings (see :help expr-.):

  • 1
    Thank you a lot for detailed answer! Jun 21, 2023 at 6:57
  • 2
    To find the help you can use :helpgrep @VladyslavRehan
    – D. Ben Knoble
    Jun 21, 2023 at 13:13
  • 1
    Yes I did :helpgrep \= followed by :cwin (to show the results in a window) then switch to that window and press "Return" on the relevant one. (Though using the website at vimhelp.org is even easier, auto-complete on the search box helps with that!)
    – filbranden
    Jun 21, 2023 at 16:27

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.