Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Here's one way:

:g/pattern/s/^/\=@a/

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

:help sub-replace-expression
:help expr-register
share|improve this answer
    
Thanks! This was what I was looking for despite my rather clumsy written question. –  johnny Dec 16 '10 at 7:56
    
:%s/^\zs.*pattern/\=@a/ will also do it. –  Luc Hermitte Dec 16 '10 at 17:32
    
@Luc, I'm pretty sure you mean \ze –  johnny Dec 28 '10 at 13:46
    
Indeed. Thanks. –  Luc Hermitte Dec 28 '10 at 14:05
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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