从搜索模式复制到 ex 模式
在“/
”模式下搜索时,如果需要复制到ex模式下怎么办?例如,我搜索了 /ab.*xy
,现在我需要它作为 %s/ab.*xy/.../g
。
我的目的是测试我的搜索,然后将其用于搜索替换
While in the "/
" mode to search, what should I do if need to copy it to the ex mode. E.g. I searched for /ab.*xy
, now I need it as %s/ab.*xy/.../g
.
My intention is to test my search and then use that for a search replace
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
/
寄存器,在ex模式下按:Ctrl-R/
Ctrl-R 允许插入寄存器的内容,
/
寄存器包含最后使用的搜索模式。Use the
/
register, in ex mode press:Ctrl-R/
Ctrl-R allows you to insert the contents of a register, and the
/
register contains the last search pattern used.或者,您可以将搜索部分留空:
如您所料,第一行找到“foo”。由于您在第二行中省略了搜索字符串,因此它只是重新使用相同的搜索,将“foo”替换为“bar”。我相信这在您键入搜索字符串的任何地方都有效 - 如果它为空,则意味着重新使用以前的搜索。
Alternatively, you can leave the search portion blank:
The first line finds "foo", as you'd expect. Since you left off the search string in the second line, it just re-uses the same search, replacing "foo" with "bar". I believe this works anywhere you type a search string -- if it's blank, that means re-use the previous search.