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.)


Sure, just leave the pattern in the substitution empty:


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.


Another possible solution

:exe '%s/' . @/ . '/replacement/g'

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.