Commenting and Uncommenting in vi

Sometimes I have to edit large config files in vi. Typically I have to comment out a block or even the whole file. Here’s the command to insert a # before every line in the file:

:%s/^/# /

To comment the next 4 lines (. is current line , . + 3 lines more)

:.,.+3s/^/# /

And to uncomment the first character from every line:


Or uncomment a section:


Updating my Raspberry Pi’s IP address on a distant server via SFTP

Now I have my external IP address, I want to collect it on a regular basis and push it to a server that accepts SFTP. Now sadly, that server doesn’t allow me to use passkey files, so I have to workaround using sshpass (a great little module allowing to pass passwords to the SSH commands – install as usual with apt-get install sshpass ).

The EOF at the end of the sftp command is to ensure that I am passing the rest of the commands to the sftp command. I could also use a -b flag and a file, but it would mean one more file to deal with.

wget -q -O- |
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' > ip.txt
sshpass -p XXXXX sftp -oPort=22 <<-EOF
cd /location
put ip.txt

Then it was a simple matter of putting that in a crontab job, running it every five minutes is enough. Calling crontab crons.txt launched the job. crontab -l lists the jobs.

*/5 * * * * ~/ >/dev/null