Commenting Lines using vim for bash,conf file etc

It was needed that I comment a number of lines in a file. The comments of a configuration file are usally like a # in the begining of the line.
So
Line 1
Line 2
Line 3
Should become

#Line 1
#Line 2
#Line 3

HOWTO:

1) Go to the First Column of the First Line.
2) Select the Block using cntl-v (for Linux) and cntl-q(for Windows, because cntl-v is mapped to paste function in gvim under windows)
3) With the Selected test, give the command :s/^/#/
4) That should do!

But vim users always look for yet another way, so I am.

2 comments:

Kannappan said...

Wont this work? sed s/^/\#/g filename

Kannappan said...

awk -F '{print"#"$n}' filename