How I can save a replace value to register or somewhere? For example


So then I can use new value.


If you have something in a register that you want to use as the replacement in a regular expression, just read it in to the :-command line at the point where you need the data by typing control-r@x where x is the name of the register you used.

Or you could use the special \= string in the replacement. When the replacement string starts with \= everything after is evaluated as an expression, so you can do something like:


Again, where x is the name of the register you used. This lets you use variables names as well:

:let new="new string"


:help c_ctrl-r
:help sub-replace-special
  • No, I want to save value that was used for replacement.
    – Yuki
    Mar 31 '13 at 1:08
  • You'd basically have to do that manually, either by putting it into a register or a variable. Vim saves the last search pattern, but not the last replace pattern.
    – Heptite
    Mar 31 '13 at 1:12

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.