7

Sometimes I want to try a pattern with / before doing :%s/ …; can I reuse it without having to type it all over? (or use the mouse.)

9

Sure, just leave the pattern in the substitution empty:

:%s//replacement/
| improve this answer | |
4

In addition to @garyjohn's answer, you can use <c-r>/ to insert the search register into a command if you want to edit it or leaving out the search pattern isn't sufficient.

:%s/<c-r>//replacement
| improve this answer | |
0

Another possible solution

:exe '%s/' . @/ . '/replacement/g'
| improve this answer | |

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.