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

1 Answer 1

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
1
  • 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). Jun 6, 2015 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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