Software >> OS >> Unix >> Utilities >> vi >> how to insert a string at beginning of each line

## Get into command mode (press Esc key if not already so)

## To replace from 1st line to last line

:1$s/^/replacementstring/

or

:%s/^/replacementstring/


## To replace from current line and next 4 lines (total 5 lines)

:.,+4s/^/replacementstring/


## To replace from current line and previous 4 lines (total 5 lines)

:.,-4s/^/replacementstring/g