Insert a string at the start of line in vi To insert something at the start of line (for all the lines in the file) when editing file (in this particular example the rm command) in vi do the following:
:1,%s/^/rm /g
Find and replace line breaks with patern in vi Sometimes you need to append something to the end of line in a text file or script. Use the following vi command (in this example append a semicolon ';' to the end of every line in the file).
:1,$s/$/;/g
vi commands Here are some vi commands.
:1,$s/old/new/g find old, replace with new
:set all show all settings
:set list display invisible characters
:set showmode display the mode
:3,8d delete lines 3-8
D delete to end of lines
J4 join 4 lines to current
:4,9m 12 move lines 4-9 to 12
:2,5t 13 copy lines 2-5 to 13
:5,9w file write lines 5-9 to file
ZZ write buffer and quit
% goto matching brace/paren
3G goto line 3
3w go ...