Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有时我会使用 进行正则表达式搜索/。但后来我想使用相同的模式进行替换,用%s. 如何复制或以其他方式重用该模式?
/
%s
例如,你做了一个
/foo
那么你可以:
%s//bar/g
vim 将所有foo(你的最后一次搜索)替换为bar
foo
bar
您最后的搜索模式存储在/寄存器中,您可以通过读取寄存器值来获取它。例如
"/p (in normal mode)
或者
<c-r>/ (in insert/command mode)