After doing


I can type


to place foo into the command line.

How can I place bar into the command line?

I ultimately want to do a series of:


etc., inspecting the resulting source file's outputs in-between (and don't want to rely on replace-undo, <C-r>/ because I might edit the file manually in-between too)

2 Answers 2


You can search for the last used substitute string with /~/. This should work as long as the substitute string does not contain any specials like \0...\9, \U, \L, etc.


<C-r>/ inserts a special register "/ (the last search string) at the actual position in the command line. Type :register and you'll see all registers with their content. There is no register for the subtitute-text.

Register are AFAIK the only way to keep such informations.

You could write a vim function, that extracts the replacement part of the substition command stored in register ": with a regular expression. You could bind that function to a key. But that only works as long as you do not enter another command, which would overwrite the ": register.

Another idea: You have to type foo, bar and baz at least once, you could instead search for them in the text, highlight them with v and yank them into a separate register:


Now you can use the registers as long as you want (as you don't overwrite them).

  • Thanks for the final alternative suggestion. Unfortunately this one won't work for me because b depends on my interpreted results of a, c on b etc.—I can't know them ahead of time. I guess your vim function idea is a good one, and thanks for introducing me to the ": register. I could first check if the contents are indeed a substitution, then rewrite my special register.
    – minseong
    Jan 26, 2021 at 13:18
  • But since it's not built into VIM, it seems likely there would exist plugins for it...
    – minseong
    Jan 26, 2021 at 13:19
  • @theonlygusti There are some interesting search and replace plugins. Perhaps you find something usefull? If you plan the compute bar from foo e.g, I'd like to point you to the expression register "= which could be helpful as it executes a random command that you store in it and prints it to the target location. brianstorti.com/vim-registers (The expression and the search registers) Jan 26, 2021 at 13:44

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.