Sometimes I do a regexp search with /
. But then I want to use the same pattern to do a replace, with %s
. How do I copy or otherwise reuse the pattern?
for example, you did a
/foo
then you could:
%s//bar/g
vim will replace all foo
(your last search) with bar
Your last search pattern was stored in /
register, you could get it by reading the register value. e.g.
"/p (in normal mode)
or
<c-r>/ (in insert/command mode)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With