How to comment all lines in VI editor ?

Author:

How to comment all lines in VI editor ?

This can be done with a using a command like ‘search and replace’

1.Open the file in ‘vi’ editor.
2.Press Escape and type :1,$s/^/##/g
3.Press Enter

1,$s/^/##/g can be broken down as
1: To start from 1st line
$s :To end at the last line
/^ : Search for the start of the line
/##:Replace with ##
/g: Replace all occurrences

contributed by : Pratik Shah

Leave a Reply

Your email address will not be published.