使用寄存器值作为搜索模式 [英] Use a register value as search pattern

查看:18
本文介绍了使用寄存器值作为搜索模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 Vim 中使用寄存器的内容作为搜索模式.

I wish to use the content of a register as search pattern in Vim.

我想从命令行执行此操作,因此我无法使用 <c-r> 语法,因为它假设了一个交互式会话.

I would like to do this from the command line so I cannot use the <c-r> syntax since that assumes an interactive session.

可以将寄存器用作替换模式,就像这样

It is possible to use a register as a replace pattern, like this

:%s/foo/\=@a/g

但是,将此语法用作搜索模式不起作用

However using this syntax as a search pattern does not work

:%s/\=@a/foo/g 

输出

E64: \= follows nothing
E476: Invalid command

推荐答案

我不认为直接可以,但是你可以使用 :exe 来实现:

I don't think it's possible directly, but you can use :exe to achieve this:

:exe '%s/' . @a . '/foo/g'

这篇关于使用寄存器值作为搜索模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆