Use a register value as search pattern

Viewed 4165

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

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 

it outputs

E64: \= follows nothing
E476: Invalid command
3 Answers
Related