vim: use string from search in replace command

In general, an empty regular expression means to use the previously entered regular expression, so :%s//\1/g should do what you want.


Another good way to see past regexes searches as well as Ex commands and make changes to them is to edit these commands in normal mode. From this Mode you will have all your vim powers including copy and paste.

  • Searching: rather than ? or / for searching, try q/ or q?
  • for Ex Commands, rather than : try q:
  • to exit this mode use CtrlC

To read more see :help q:.