2

If I have something stored in the named register n, then from the normal mode hitting

/<C-R>n

would search for what is stored inside the register.

But suppose I want to write a function which searches for what is stored in the n register. What do I do?

I tried

function! SearchTheDataInnReg()
   <C-R>l
endfunction

I get an error message:

E488: Trailing characters: <09><C-R>l
4

From function you can access to named registers via @. For explanation :he let-@ and similars topics. For search pattern call search() function.

Your code may look like this. In this example we search pattern in l register.

func! SearchTheDataInnReg()
    call search(@l)
endfunc
  • 3
    You can use execute '/' . @l if you want exactly the same behaviour as typing /<C-r>l. search() behaves subtly different on some points (which may be considered desirable or undesirable depending on what you're doing). – Martin Tournoij Jun 6 '15 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.