Friday, February 4, 2011

vim comment lines

In linux, while editing configuration files, we always used # sign for comments. How do we do it to multiple lines in vi easily?

Steps:

1. Edit the files using vi
$ vi files.conf

2. set line number in vi (for us to easily determine what is the line number that we want to edit)
:se nu

3. replace start of lines with # (for example, put # sign in front of line 2 to line 5). The meaning of below command is for line 2 - 5, subtitute (s) start of line (^) with # sign, and press enter
:2,5s/^/#/
<enter>

4. It is done. Save your file (w) and quit (q)
:wq