Home > CentOS, Linux, Red Hat, Solaris, Ubuntu > Using VI Editor to insert at the beginning/end of each line

Using VI Editor to insert at the beginning/end of each line

This replaces the beginning of each line with “replace”:

:%s!^!replace!

This replaces the beginning of each selected line (use visual mode to select) with “replace”:

:'<,’>s!^!replace!
YES you can change the symbol ! to /

:%s/^/replace/
:'<,’>s/^/replace/

This replaces the end of each  line

:%s/$/replace/g

 

 

Categories: CentOS, Linux, Red Hat, Solaris, Ubuntu
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment