Project

General

Profile

Feature #664

Updated by Daniel Curtis about 5 years ago

This is a simple guide on using vi to insert a comment character in front of every line of a given range of line in a text file. I find this extremely useful for testing various blocks of code or configuration files.

* Open a file file with vi:
<pre>
vi /home/user/sometext.conf
</pre>

* Show line numbers in vi:
<pre>
:set number
</pre>

* To add a # character in front of lines 34-65:
<pre>
:34,65s/^/#
</pre>

* To remove the # character from the beginning of lines 78-102:
<pre>
:78,102s/^#/
</pre>

h2. Resources

* http://unix.stackexchange.com/questions/120615/how-to-comment-multiple-lines-at-once

Back