Anyone know if it's possible in vi to replace only uncommented/non-blank lines with comments?
If I want to replace a commented line with something I know I can use :%s/^#/##foo##/g — but I am looking for the opposite of this.
Example file:
# Some user's cron
# Test comments
00 00 * * * ~/somescript.sh
Expected result:
# Some user's cron
# Test comments
##DISABLE##00 00 * * * ~/somescript.sh
Best Answer
This "g/RE/" part selects all lines that begin with a number or the * character. The "s/RE/replacement/" then does the work on all selected lines.