2

I want to paste the same text at the start of some lines of my document all at once.

[For example]
-Before-

'1','North America'
'2','South America'
'3','Europe'

-After-

INSERT INTO 'continent' ('id' ,'name') VALUES ('1','North America'
INSERT INTO 'continent' ('id' ,'name') VALUES ('2','South America'
INSERT INTO 'continent' ('id' ,'name') VALUES ('3','Europe'

Please tell me if there is a way of doing this.
Thanks!

user1055604
  • 1,624
  • 11
  • 28
Daniel
  • 45
  • 3

2 Answers2

3

Go to the first character, CTRL-V (switch to visual blockwise selection), jj (to move down two lines), I (capital i, switches to insert before block), and then CTRL-R" to instert contents of the default register. When you hit ESCAPE you will see that the text that you've inserted appears on all other lines.

Benoit
  • 76,634
  • 23
  • 210
  • 236
2

Try this:

:%s/^/INSERT INTO 'continent' ('id' ,'name') VALUES (/

% stands for the whole document. You can replace the % with range. For example

 :1,4s/^/INSERT INTO 'continent' ('id' ,'name') VALUES (/

will insert only at the begining of the first 4 lines.

Molecular Man
  • 22,277
  • 3
  • 72
  • 89