Is there a way to tell (g)Vim to insert from register at the beginning of a row? I know I can use s/^/[text]/ but I was thinking more along the lines of :g/[text]/ "+p except that that doesn't work. I guess the problem is that there's no way for Vim to decide where to put the content of the register.

2 Answers 2


Here's one way:


will insert the contents of register a at the start of every line containing pattern. See

:help sub-replace-expression
:help expr-register
  • 1
    :%s/^\zs.*pattern/\=@a/ will also do it. Dec 16, 2010 at 17:32
  • 1
    @Luc, I'm pretty sure you mean \ze
    – johnny
    Dec 28, 2010 at 13:46

You can use P to paste before cursor (and p to paste after).

So if you got at the beginning of a row with 0 or ^, you can they use "+P.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .