How to insert a word/text in the beginning of each line [duplicate]

The command:

:%s/^/foo: /

…inserts foo: (including a trailing space) at the beginning of each line.

For a range you can use line numbers:

:10,20s/^/foo: /

…will do it for line 10 to 20.

My preferred way to do it for a range of lines is this: move the cursor to the first line of the range, then enter ma to set the marker a to the current line. Move to the end of the range and enter

:'a,.s/^/foo: /

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)